Commit 77189c5b authored by Markus Kalkbrenner's avatar Markus Kalkbrenner Committed by Markus Kalkbrenner
Browse files

Issue #3268614 by mkalkbrenner: Add configuration whether parents should be...

Issue #3268614 by mkalkbrenner: Add configuration whether parents should be included in "Show siblings" processor or not
parent 57ba7bba
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -127,6 +127,14 @@ plugin.plugin_configuration.facets_processor.dependent_processor:
        type: boolean
        label: 'Should the condition be negated'

plugin.plugin_configuration.facets_processor.show_siblings_processor:
  type: mapping
  label: 'Show siblings processor'
  mapping:
    show_parent_siblings:
      type: boolean
      label: 'Show parents'

plugin.plugin_configuration.facets_processor.date_item:
  type: mapping
  label: 'Date item processor'
+30 −4
Original line number Diff line number Diff line
@@ -2,20 +2,21 @@

namespace Drupal\facets\Plugin\facets\processor;

use Drupal\Core\Form\FormStateInterface;
use Drupal\facets\FacetInterface;
use Drupal\facets\Processor\BuildProcessorInterface;
use Drupal\facets\Processor\ProcessorPluginBase;
use Drupal\facets\Result\Result;

/**
 * Provides a processor that only shows deepest level items.
 * Provides a processor that adds all siblings of the active item to the result.
 *
 * @FacetsProcessor(
 *   id = "show_siblings_processor",
 *   label = @Translation("Show siblings"),
 *   description = @Translation("Show all siblings of a hierarchical facet item. In 'Advanced settings' this processor should be executed early in the processor chain, for example before ids get converted into titles. It is recommended to enable 'Use hierarchy' and 'Ensure that only one result can be displayed', too."),
 *   description = @Translation("Show all siblings of a hierarchical facet item. In 'Advanced settings' this processor should be executed early in the processor chain, for example before the URL handler and before ids get converted into titles. It is recommended to enable 'Use hierarchy' and 'Ensure that only one result can be displayed', too."),
 *   stages = {
 *     "build" = 40
 *     "build" = 11
 *   }
 * )
 */
@@ -30,11 +31,36 @@ class ShowSiblingsProcessor extends ProcessorPluginBase implements BuildProcesso
      $rawValues = array_map(function ($result) {
        return $result->getRawValue();
      }, $results);
      foreach ($facet->getHierarchyInstance()->getSiblingIds($rawValues, $facet->getActiveItems()) as $siblingId) {
      foreach ($facet->getHierarchyInstance()->getSiblingIds($rawValues, $facet->getActiveItems(), $this->getConfiguration()['show_parent_siblings']) as $siblingId) {
        $results[] = new Result($facet, $siblingId, $siblingId, 0);
      }
    }
    return $results;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'show_parent_siblings' => TRUE,
    ] + parent::defaultConfiguration();
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
    $configuration = $this->getConfiguration();

    $build['show_parent_siblings'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Show parent siblings'),
      '#description' => $this->t('If selected the siblings of all (inactive) parents of an active item will be added be shown. Otherwise only the siblings of active items will be shown. (See "Keep hierarchy parents active".)'),
      '#default_value' => $configuration['show_parent_siblings'],
    ];

    return $build;
  }

}