facets-8.x-1.x-dev/src/Plugin/facets/processor/HideActiveItemsProcessor.php

src/Plugin/facets/processor/HideActiveItemsProcessor.php
<?php

namespace Drupal\facets\Plugin\facets\processor;

use Drupal\Core\Cache\UnchangingCacheableDependencyTrait;
use Drupal\facets\FacetInterface;
use Drupal\facets\Processor\BuildProcessorInterface;
use Drupal\facets\Processor\ProcessorPluginBase;

/**
 * Provides a processor that hides results that don't narrow results.
 *
 * @FacetsProcessor(
 *   id = "hide_active_items_processor",
 *   label = @Translation("Hide active items"),
 *   description = @Translation("Do not display items that are active."),
 *   stages = {
 *     "build" = 25
 *   }
 * )
 */
class HideActiveItemsProcessor extends ProcessorPluginBase implements BuildProcessorInterface {

  use UnchangingCacheableDependencyTrait;

  /**
   * {@inheritdoc}
   */
  public function build(FacetInterface $facet, array $results) {

    /** @var \Drupal\facets\Result\ResultInterface $result */
    foreach ($results as $id => $result) {
      if ($result->isActive()) {
        unset($results[$id]);
      }
    }

    return $results;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc