You are here

class Facet in Facets 8

Defines the facet configuration entity.

Plugin annotation


@ConfigEntityType(
  id = "facets_facet",
  label = @Translation("Facet"),
  handlers = {
    "storage" = "Drupal\Core\Config\Entity\ConfigEntityStorage",
    "list_builder" = "Drupal\facets\FacetListBuilder",
    "form" = {
      "default" = "Drupal\facets\Form\FacetSettingsForm",
      "edit" = "Drupal\facets\Form\FacetForm",
      "settings" = "Drupal\facets\Form\FacetSettingsForm",
      "clone" = "Drupal\facets\Form\FacetCloneForm",
      "delete" = "Drupal\Core\Entity\EntityDeleteForm",
    },
  },
  admin_permission = "administer facets",
  config_prefix = "facet",
  entity_keys = {
    "id" = "id",
    "label" = "name",
    "uuid" = "uuid",
    "status" = "status",
    "weight" = "weight"
  },
  config_export = {
    "id",
    "name",
    "url_alias",
    "weight",
    "min_count",
    "show_only_one_result",
    "field_identifier",
    "facet_source_id",
    "widget",
    "query_operator",
    "use_hierarchy",
    "keep_hierarchy_parents_active",
    "expand_hierarchy",
    "enable_parent_when_child_gets_disabled",
    "hard_limit",
    "exclude",
    "only_visible_when_facet_source_is_visible",
    "processor_configs",
    "empty_behavior",
    "show_title"
  },
  links = {
    "collection" = "/admin/config/search/facets",
    "add-form" = "/admin/config/search/facets/add-facet",
    "edit-form" = "/admin/config/search/facets/{facets_facet}/edit",
    "settings-form" = "/admin/config/search/facets/{facets_facet}/settings",
    "clone-form" = "/admin/config/search/facets/{facets_facet}/clone",
    "delete-form" = "/admin/config/search/facets/{facets_facet}/delete",
  }
)

Hierarchy

Expanded class hierarchy of Facet

40 files declare their use of Facet
ActiveWidgetOrderProcessorTest.php in tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
ArrayWidgetTest.php in tests/src/Unit/Plugin/widget/ArrayWidgetTest.php
BlockTestTrait.php in tests/src/Functional/BlockTestTrait.php
BooleanItemProcessorTest.php in tests/src/Unit/Plugin/processor/BooleanItemProcessorTest.php
CountLimitProcessorTest.php in tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php

... See full list

5 string references to 'Facet'
FacetBlockDeriver::getDerivativeDefinitions in src/Plugin/Block/FacetBlockDeriver.php
Gets the definition of all derivatives of a base plugin.
FacetListBuilder::buildRow in src/FacetListBuilder.php
Builds a row for an entity in the entity listing.
facets.facet.schema.yml in config/schema/facets.facet.schema.yml
config/schema/facets.facet.schema.yml
facets_summary.facets_summary.schema.yml in modules/facets_summary/config/schema/facets_summary.facets_summary.schema.yml
modules/facets_summary/config/schema/facets_summary.facets_summary.schema.yml
UrlIntegrationTest::testFacetUrlCanBeChanged in tests/src/Functional/UrlIntegrationTest.php
Tests that modules can change the facet url.

File

src/Entity/Facet.php, line 70

Namespace

Drupal\facets\Entity
View source
class Facet extends ConfigEntityBase implements FacetInterface {

  /**
   * The ID of the facet.
   *
   * @var string
   */
  protected $id;

  /**
   * A name to be displayed for the facet.
   *
   * @var string
   */
  protected $name;

  /**
   * The name for the parameter when used in the URL.
   *
   * @var string
   */
  protected $url_alias;

  /**
   * A string describing the facet.
   *
   * @var string
   */
  protected $description;

  /**
   * The widget plugin definition.
   *
   * @var array
   */
  protected $widget;

  /**
   * The widget plugin instance.
   *
   * @var \Drupal\facets\Widget\WidgetPluginBase
   */
  protected $widgetInstance;

  /**
   * The hierarchy definition.
   *
   * @var array
   */
  protected $hierarchy;

  /**
   * The hierarchy instance.
   *
   * @var \Drupal\facets\Hierarchy\HierarchyPluginBase
   */
  protected $hierarchy_processor;

  /**
   * The operator to hand over to the query, currently AND | OR.
   *
   * @var string
   */
  protected $query_operator;

  /**
   * Hard limit for the facet items.
   *
   * @var int
   */
  protected $hard_limit;

  /**
   * A boolean flag indicating if search should exclude selected facets.
   *
   * @var bool
   */
  protected $use_hierarchy = FALSE;

  /**
   * A boolean flag indicating if the parent results of a hierarchical facet
   * should be kept active when a child becomes active.
   *
   * @var bool
   */
  protected $keep_hierarchy_parents_active = FALSE;

  /**
   * A boolean indicating if hierarchical items should always be expanded.
   *
   * @var bool
   */
  protected $expand_hierarchy = FALSE;

  /**
   * Wether or not parents should be enabled when a child gets disabled.
   *
   * @var bool
   */
  protected $enable_parent_when_child_gets_disabled = TRUE;

  /**
   * A boolean flag indicating if search should exclude selected facets.
   *
   * @var bool
   */
  protected $exclude = FALSE;

  /**
   * The field identifier.
   *
   * @var string
   */
  protected $field_identifier;

  /**
   * The id of the facet source.
   *
   * @var string
   */
  protected $facet_source_id;

  /**
   * The facet source belonging to this facet.
   *
   * @var \Drupal\facets\FacetSource\FacetSourcePluginInterface
   *
   * @see getFacetSource()
   */
  protected $facet_source_instance = NULL;

  /**
   * The path all the links should point to.
   *
   * @var string
   */
  protected $path;

  /**
   * The results.
   *
   * @var \Drupal\facets\Result\ResultInterface[]
   */
  protected $results = [];

  /**
   * An array of active values.
   *
   * @var string[]
   */
  protected $active_values = [];

  /**
   * An array containing the facet source plugins.
   *
   * @var array
   */
  protected $facetSourcePlugins;

  /**
   * Cached information about the processors available for this facet.
   *
   * @var \Drupal\facets\Processor\ProcessorInterface[]|null
   *
   * @see loadProcessors()
   */
  protected $processors;

  /**
   * Configuration for the processors. This is an array of arrays.
   *
   * @var array
   */
  protected $processor_configs = [];

  /**
   * Is the facet only visible when the facet source is only visible.
   *
   * A boolean that defines whether or not the facet is only visible when the
   * facet source is visible.
   *
   * @var bool
   */
  protected $only_visible_when_facet_source_is_visible;

  /**
   * Determines if only one result can be selected in the facet at one time.
   *
   * @var bool
   */
  protected $show_only_one_result = FALSE;

  /**
   * The no-result configuration.
   *
   * @var string[]
   */
  protected $empty_behavior;

  /**
   * The widget plugin manager.
   *
   * @var \Drupal\facets\Widget\WidgetPluginManager
   */
  protected $widget_plugin_manager;

  /**
   * The hierarchy plugin manager.
   *
   * @var \Drupal\facets\Hierarchy\HierarchyPluginManager
   *   The hierarchy plugin manager.
   */
  protected $hierarchy_manager;

  /**
   * The facet source config object.
   *
   * @var \Drupal\Facets\FacetSourceInterface
   *   The facet source config object.
   */
  protected $facetSourceConfig;

  /**
   * The facet weight.
   *
   * @var int
   *   The weight of the facet.
   */
  protected $weight;

  /**
   * The minimum amount of results to show.
   *
   * @var int
   *   The minimum amount of results.
   */
  protected $min_count = 1;

  /**
   * Returns the widget plugin manager.
   *
   * @return \Drupal\facets\Widget\WidgetPluginManager
   *   The widget plugin manager.
   */
  public function getWidgetManager() {
    return $this->widget_plugin_manager ?: \Drupal::service('plugin.manager.facets.widget');
  }

  /**
   * Returns the hierarchy plugin manager.
   *
   * @return \Drupal\facets\Hierarchy\HierarchyPluginManager
   *   The hierarchy plugin manager.
   */
  public function getHierarchyManager() {
    return $this->hierarchy_manager ?: \Drupal::service('plugin.manager.facets.hierarchy');
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this->description;
  }

  /**
   * {@inheritdoc}
   */
  public function setWidget($id, array $configuration = NULL) {
    if ($configuration === NULL) {
      $instance = $this
        ->getWidgetManager()
        ->createInstance($id);

      // Get the default configuration for this plugin.
      $configuration = $instance
        ->getConfiguration();
    }
    $this->widget = [
      'type' => $id,
      'config' => $configuration,
    ];

    // Unset the widget instance, if exists.
    unset($this->widgetInstance);
  }

  /**
   * {@inheritdoc}
   */
  public function getWidget() {
    return $this->widget;
  }

  /**
   * {@inheritdoc}
   */
  public function getWidgetInstance() {
    if ($this->widget === NULL) {
      throw new InvalidProcessorException();
    }
    if (!isset($this->widgetInstance)) {
      $definition = $this
        ->getWidget();
      $this->widgetInstance = $this
        ->getWidgetManager()
        ->createInstance($definition['type'], (array) $definition['config']);
    }
    return $this->widgetInstance;
  }

  /**
   * {@inheritdoc}
   */
  public function setHierarchy($id, array $configuration = NULL) {
    if ($configuration === NULL) {
      $instance = $this
        ->getHierarchyManager()
        ->createInstance($id);

      // Get the default configuration for this plugin.
      $configuration = $instance
        ->getConfiguration();
    }
    $this->hierarchy = [
      'type' => $id,
      'config' => $configuration,
    ];

    // Unset the hierarchy instance, if exists.
    unset($this->hierarchy_instance);
  }

  /**
   * {@inheritdoc}
   */
  public function getHierarchy() {

    // TODO: do not hardcode on taxonomy, make this configurable (or better,
    // autoselected depending field type).
    return [
      'type' => 'taxonomy',
      'config' => [],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getHierarchyInstance() {
    if (!isset($this->hierarchy_instance)) {
      $definition = $this
        ->getHierarchy();
      $this->hierarchy_instance = $this
        ->getHierarchyManager()
        ->createInstance($definition['type'], (array) $definition['config']);
    }
    return $this->hierarchy_instance;
  }

  /**
   * Retrieves all processors supported by this facet.
   *
   * @return \Drupal\facets\Processor\ProcessorInterface[]
   *   The loaded processors, keyed by processor ID.
   */
  protected function loadProcessors() {
    if (is_array($this->processors)) {
      return $this->processors;
    }

    /* @var $processor_plugin_manager \Drupal\facets\Processor\ProcessorPluginManager */
    $processor_plugin_manager = \Drupal::service('plugin.manager.facets.processor');
    $processor_settings = $this
      ->getProcessorConfigs();
    foreach ($processor_plugin_manager
      ->getDefinitions() as $name => $processor_definition) {
      if (class_exists($processor_definition['class']) && empty($this->processors[$name])) {

        // Create our settings for this processor.
        $settings = empty($processor_settings[$name]['settings']) ? [] : $processor_settings[$name]['settings'];
        $settings['facet'] = $this;

        /* @var $processor \Drupal\facets\Processor\ProcessorInterface */
        $processor = $processor_plugin_manager
          ->createInstance($name, $settings);
        $this->processors[$name] = $processor;
      }
      elseif (!class_exists($processor_definition['class'])) {
        \Drupal::logger('facets')
          ->warning('Processor @id specifies a non-existing @class.', [
          '@id' => $name,
          '@class' => $processor_definition['class'],
        ]);
      }
    }
    return $this->processors;
  }

  /**
   * {@inheritdoc}
   */
  public function getProcessorConfigs() {
    return !empty($this->processor_configs) ? $this->processor_configs : [];
  }

  /**
   * {@inheritdoc}
   */
  public function getQueryType() {
    $facet_source = $this
      ->getFacetSource();
    if (is_null($facet_source)) {
      throw new Exception("No facet source defined for facet.");
    }
    $query_types = $facet_source
      ->getQueryTypesForFacet($this);

    // Get the widget configured for this facet.

    /** @var \Drupal\facets\Widget\WidgetPluginInterface $widget */
    $widget = $this
      ->getWidgetInstance();

    // Give the widget the chance to select a preferred query type. This is
    // needed for widget that have different query type. For example the need
    // for a range query.
    $widgetQueryType = $widget
      ->getQueryType();

    // Allow widgets to also specify a query type.
    $processorQueryTypes = [];
    foreach ($this
      ->getProcessors() as $processor) {
      $pqt = $processor
        ->getQueryType();
      if ($pqt !== NULL) {
        $processorQueryTypes[] = $pqt;
      }
    }
    $processorQueryTypes = array_flip($processorQueryTypes);

    // The widget has made no decision and neither have the processors.
    if ($widgetQueryType === NULL && count($processorQueryTypes) === 0) {
      return $this
        ->pickQueryType($query_types, 'string');
    }

    // The widget has made no decision but the processors have made 1 decision.
    if ($widgetQueryType === NULL && count($processorQueryTypes) === 1) {
      return $this
        ->pickQueryType($query_types, key($processorQueryTypes));
    }

    // The widget has made a decision and the processors have not.
    if ($widgetQueryType !== NULL && count($processorQueryTypes) === 0) {
      return $this
        ->pickQueryType($query_types, $widgetQueryType);
    }

    // The widget has made a decision and the processors have 1, being the same.
    if ($widgetQueryType !== NULL && count($processorQueryTypes) === 1 && key($processorQueryTypes) === $widgetQueryType) {
      return $this
        ->pickQueryType($query_types, $widgetQueryType);
    }

    // Invalid choice.
    throw new InvalidQueryTypeException("Invalid query type combination in widget / processors. Widget: {$widgetQueryType}, Processors: " . implode(', ', array_keys($processorQueryTypes)) . ".");
  }

  /**
   * Choose the query type.
   *
   * @param array $allTypes
   *   An array of query type definitions.
   * @param string $type
   *   The chose query type.
   *
   * @return string
   *   The class name of the chose query type.
   *
   * @throws \Drupal\facets\Exception\InvalidQueryTypeException
   */
  protected function pickQueryType(array $allTypes, $type) {
    if (!isset($allTypes[$type])) {
      throw new InvalidQueryTypeException("Query type {$type} doesn't exist.");
    }
    return $allTypes[$type];
  }

  /**
   * {@inheritdoc}
   */
  public function setQueryOperator($operator = '') {
    return $this->query_operator = $operator;
  }

  /**
   * {@inheritdoc}
   */
  public function getQueryOperator() {
    return $this->query_operator ?: 'or';
  }

  /**
   * {@inheritdoc}
   */
  public function setUseHierarchy($use_hierarchy) {
    return $this->use_hierarchy = $use_hierarchy;
  }

  /**
   * {@inheritdoc}
   */
  public function getUseHierarchy() {
    return $this->use_hierarchy;
  }

  /**
   * {@inheritdoc}
   */
  public function setKeepHierarchyParentsActive($keep_hierarchy_parents_active) {
    return $this->keep_hierarchy_parents_active = $keep_hierarchy_parents_active;
  }

  /**
   * {@inheritdoc}
   */
  public function getKeepHierarchyParentsActive() {
    return $this->keep_hierarchy_parents_active;
  }

  /**
   * {@inheritdoc}
   */
  public function setExpandHierarchy($expand_hierarchy) {
    return $this->expand_hierarchy = $expand_hierarchy;
  }

  /**
   * {@inheritdoc}
   */
  public function getExpandHierarchy() {
    return $this->expand_hierarchy;
  }

  /**
   * {@inheritdoc}
   */
  public function setEnableParentWhenChildGetsDisabled($enable_parent_when_child_gets_disabled) {
    return $this->enable_parent_when_child_gets_disabled = $enable_parent_when_child_gets_disabled;
  }

  /**
   * {@inheritdoc}
   */
  public function getEnableParentWhenChildGetsDisabled() {
    return $this->enable_parent_when_child_gets_disabled;
  }

  /**
   * {@inheritdoc}
   */
  public function setHardLimit($limit) {
    return $this->hard_limit = $limit;
  }

  /**
   * {@inheritdoc}
   */
  public function getHardLimit() {
    return $this->hard_limit ?: 0;
  }

  /**
   * {@inheritdoc}
   */
  public function getDataDefinition() {
    return $this
      ->getFacetSource()
      ->getDataDefinition($this->field_identifier);
  }

  /**
   * {@inheritdoc}
   */
  public function setExclude($exclude) {
    return $this->exclude = $exclude;
  }

  /**
   * {@inheritdoc}
   */
  public function getExclude() {
    return $this->exclude;
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldAlias() {

    // For now, create the field alias based on the field identifier.
    $field_alias = preg_replace('/[:\\/]+/', '_', $this->field_identifier);
    return $field_alias;
  }

  /**
   * {@inheritdoc}
   */
  public function setActiveItem($value) {
    if (!in_array($value, $this->active_values)) {
      $this->active_values[] = $value;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getActiveItems() {
    return $this->active_values;
  }

  /**
   * {@inheritdoc}
   */
  public function setActiveItems(array $values) {
    $this->active_values = $values;
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldIdentifier() {
    return $this->field_identifier;
  }

  /**
   * {@inheritdoc}
   */
  public function setFieldIdentifier($field_identifier) {
    $this->field_identifier = $field_identifier;
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return $this->name;
  }

  /**
   * {@inheritdoc}
   */
  public function getUrlAlias() {
    return $this->url_alias;
  }

  /**
   * {@inheritdoc}
   */
  public function setUrlAlias($url_alias) {
    $this->url_alias = $url_alias;
  }

  /**
   * {@inheritdoc}
   */
  public function setFacetSourceId($facet_source_id) {
    $this->facet_source_id = $facet_source_id;
  }

  /**
   * {@inheritdoc}
   */
  public function getFacetSourceId() {
    return $this->facet_source_id;
  }

  /**
   * {@inheritdoc}
   */
  public function getFacetSource() {
    if (is_null($this->facet_source_instance) && $this->facet_source_id) {

      /* @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
      $facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
      if (!$facet_source_plugin_manager
        ->hasDefinition($this->facet_source_id)) {
        return NULL;
      }
      $this->facet_source_instance = $facet_source_plugin_manager
        ->createInstance($this->facet_source_id, [
        'facet' => $this,
      ]);
    }
    return $this->facet_source_instance;
  }

  /**
   * {@inheritdoc}
   */
  public function getShowOnlyOneResult() {
    return $this->show_only_one_result;
  }

  /**
   * {@inheritdoc}
   */
  public function setShowOnlyOneResult($show_only_one_result) {
    $this->show_only_one_result = $show_only_one_result;
  }

  /**
   * {@inheritdoc}
   */
  public function getFacetSourceConfig() {

    // Return the facet source config object, if it's already set on the facet.
    if ($this->facetSourceConfig instanceof FacetSource) {
      return $this->facetSourceConfig;
    }
    $storage = \Drupal::entityTypeManager()
      ->getStorage('facets_facet_source');
    $source_id = str_replace(':', '__', $this->facet_source_id);

    // Load and return the facet source config object from the storage.
    $facet_source = $storage
      ->load($source_id);
    if ($facet_source instanceof FacetSource) {
      $this->facetSourceConfig = $facet_source;
      return $this->facetSourceConfig;
    }

    // We didn't have a facet source config entity yet for this facet source
    // plugin, so we create it on the fly.
    $facet_source = new FacetSource([
      'id' => $source_id,
      'name' => $this->facet_source_id,
      'filter_key' => 'f',
      'url_processor' => 'query_string',
    ], 'facets_facet_source');
    return $facet_source;
  }

  /**
   * {@inheritdoc}
   */
  public function getResults() {
    return $this->results;
  }

  /**
   * {@inheritdoc}
   */
  public function setResults(array $results) {
    $this->results = $results;

    // If there are active values,
    // set the results which are active to active.
    if (count($this->active_values)) {
      foreach ($this->results as $result) {
        if (in_array($result
          ->getRawValue(), $this->active_values)) {
          $result
            ->setActiveState(TRUE);
        }
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function isActiveValue($value) {
    $is_active = FALSE;
    if (in_array($value, $this->active_values)) {
      $is_active = TRUE;
    }
    return $is_active;
  }

  /**
   * {@inheritdoc}
   */
  public function getFacetSources($only_enabled = FALSE) {
    if (!isset($this->facetSourcePlugins)) {
      $this->facetSourcePlugins = [];

      /* @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
      $facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
      foreach ($facet_source_plugin_manager
        ->getDefinitions() as $name => $facet_source_definition) {
        if (class_exists($facet_source_definition['class']) && empty($this->facetSourcePlugins[$name])) {

          // Create our settings for this facet source..
          $config = isset($this->facetSourcePlugins[$name]) ? $this->facetSourcePlugins[$name] : [];

          /* @var $facet_source \Drupal\facets\FacetSource\FacetSourcePluginInterface */
          $facet_source = $facet_source_plugin_manager
            ->createInstance($name, $config);
          $this->facetSourcePlugins[$name] = $facet_source;
        }
        elseif (!class_exists($facet_source_definition['class'])) {
          \Drupal::logger('facets')
            ->warning('Facet Source @id specifies a non-existing @class.', [
            '@id' => $name,
            '@class' => $facet_source_definition['class'],
          ]);
        }
      }
    }

    // Filter facet sources by status if required.
    if (!$only_enabled) {
      return $this->facetSourcePlugins;
    }
    return array_intersect_key($this->facetSourcePlugins, array_flip($this->facetSourcePlugins));
  }

  /**
   * {@inheritdoc}
   */
  public function getProcessors($only_enabled = TRUE) {
    $processors = $this
      ->loadProcessors();

    // Filter processors by status if required. Enabled processors are those
    // which have settings in the processor_configs.
    if ($only_enabled) {
      $processors_settings = $this
        ->getProcessorConfigs();
      $processors = array_intersect_key($processors, $processors_settings);
    }
    return $processors;
  }

  /**
   * {@inheritdoc}
   */
  public function getProcessorsByStage($stage, $only_enabled = TRUE) {
    $processors = $this
      ->getProcessors($only_enabled);
    $processor_settings = $this
      ->getProcessorConfigs();
    $processor_weights = [];

    // Get a list of all processors for given stage.
    foreach ($processors as $name => $processor) {
      if ($processor
        ->supportsStage($stage)) {
        if (!empty($processor_settings[$name]['weights'][$stage])) {
          $processor_weights[$name] = $processor_settings[$name]['weights'][$stage];
        }
        else {
          $processor_weights[$name] = $processor
            ->getDefaultWeight($stage);
        }
      }
    }

    // Sort requested processors by weight.
    asort($processor_weights);
    $return_processors = [];
    foreach ($processor_weights as $name => $weight) {
      $return_processors[$name] = $processors[$name];
    }
    return $return_processors;
  }

  /**
   * {@inheritdoc}
   */
  public function setOnlyVisibleWhenFacetSourceIsVisible($only_visible_when_facet_source_is_visible) {
    $this->only_visible_when_facet_source_is_visible = $only_visible_when_facet_source_is_visible;
  }

  /**
   * {@inheritdoc}
   */
  public function getOnlyVisibleWhenFacetSourceIsVisible() {
    return $this->only_visible_when_facet_source_is_visible;
  }

  /**
   * {@inheritdoc}
   */
  public function addProcessor(array $processor) {
    $this->processor_configs[$processor['processor_id']] = [
      'processor_id' => $processor['processor_id'],
      'weights' => $processor['weights'],
      'settings' => $processor['settings'],
    ];

    // Sort the processors so we won't have unnecessary changes.
    ksort($this->processor_configs);
  }

  /**
   * {@inheritdoc}
   */
  public function removeProcessor($processor_id) {
    unset($this->processor_configs[$processor_id]);
    unset($this->processors[$processor_id]);
  }

  /**
   * {@inheritdoc}
   */
  public function getEmptyBehavior() {
    return $this->empty_behavior;
  }

  /**
   * {@inheritdoc}
   */
  public function setEmptyBehavior(array $empty_behavior) {
    $this->empty_behavior = $empty_behavior;
  }

  /**
   * {@inheritdoc}
   */
  public function getWeight() {
    return $this->weight;
  }

  /**
   * {@inheritdoc}
   */
  public function setWeight($weight) {
    $this->weight = $weight;
  }

  /**
   * {@inheritdoc}
   */
  public function setMinCount($min_count) {
    $this->min_count = $min_count;
  }

  /**
   * {@inheritdoc}
   */
  public function getMinCount() {
    return $this->min_count;
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    parent::calculateDependencies();
    $source = $this
      ->getFacetSource();
    if ($source === NULL) {
      return $this;
    }
    $facet_dependencies = $source
      ->calculateDependencies();
    if (!empty($facet_dependencies)) {
      $this
        ->addDependencies($facet_dependencies);
    }
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    parent::postSave($storage, $update);
    if (!$update) {
      self::clearBlockCache();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage, $entities);
    self::clearBlockCache();
  }

  /**
   * Clear the block cache.
   *
   * This includes resetting the shared plugin block manager as this can result
   * in the block definition cache being rebuilt in the same request with stale
   * static caches in the deriver.
   */
  protected static function clearBlockCache() {
    $container = \Drupal::getContainer();

    // If the block manager has already been loaded, we may have stale static
    // caches in the facet deriver, so lets clear it out.
    $container
      ->set('plugin.manager.block', NULL);

    // Now rebuild the cache to force a fresh set of data.
    $container
      ->get('plugin.manager.block')
      ->clearCachedDefinitions();
  }

  /**
   * Remove the facet lazy built data when the facet is serialized.
   */
  public function __sleep() {
    unset($this->facet_source_instance);
    unset($this->processors);
    return parent::__sleep();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ConfigEntityBase::$isUninstalling private property Whether the config is being deleted by the uninstall process.
ConfigEntityBase::$langcode protected property The language code of the entity's default language.
ConfigEntityBase::$originalId protected property The original ID of the configuration entity.
ConfigEntityBase::$status protected property The enabled/disabled status of the configuration entity. 4
ConfigEntityBase::$third_party_settings protected property Third party entity settings.
ConfigEntityBase::$trustedData protected property Trust supplied data and not use configuration schema on save.
ConfigEntityBase::$uuid protected property The UUID for this entity.
ConfigEntityBase::$_core protected property Information maintained by Drupal core about configuration.
ConfigEntityBase::addDependency protected function Overrides \Drupal\Core\Entity\DependencyTrait:addDependency().
ConfigEntityBase::createDuplicate public function Creates a duplicate of the entity. Overrides EntityBase::createDuplicate 1
ConfigEntityBase::disable public function Disables the configuration entity. Overrides ConfigEntityInterface::disable 1
ConfigEntityBase::enable public function Enables the configuration entity. Overrides ConfigEntityInterface::enable
ConfigEntityBase::get public function Returns the value of a property. Overrides ConfigEntityInterface::get
ConfigEntityBase::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. Overrides EntityBase::getCacheTagsToInvalidate 1
ConfigEntityBase::getConfigDependencyName public function Gets the configuration dependency name. Overrides EntityBase::getConfigDependencyName
ConfigEntityBase::getConfigManager protected static function Gets the configuration manager.
ConfigEntityBase::getConfigTarget public function Gets the configuration target identifier for the entity. Overrides EntityBase::getConfigTarget
ConfigEntityBase::getDependencies public function Gets the configuration dependencies. Overrides ConfigEntityInterface::getDependencies
ConfigEntityBase::getOriginalId public function Gets the original ID. Overrides EntityBase::getOriginalId
ConfigEntityBase::getThirdPartyProviders public function Gets the list of third parties that store information. Overrides ThirdPartySettingsInterface::getThirdPartyProviders
ConfigEntityBase::getThirdPartySetting public function Gets the value of a third-party setting. Overrides ThirdPartySettingsInterface::getThirdPartySetting
ConfigEntityBase::getThirdPartySettings public function Gets all third-party settings of a given module. Overrides ThirdPartySettingsInterface::getThirdPartySettings
ConfigEntityBase::getTypedConfig protected function Gets the typed config manager.
ConfigEntityBase::hasTrustedData public function Gets whether on not the data is trusted. Overrides ConfigEntityInterface::hasTrustedData
ConfigEntityBase::invalidateTagsOnDelete protected static function Override to never invalidate the individual entities' cache tags; the config system already invalidates them. Overrides EntityBase::invalidateTagsOnDelete
ConfigEntityBase::invalidateTagsOnSave protected function Override to never invalidate the entity's cache tag; the config system already invalidates it. Overrides EntityBase::invalidateTagsOnSave
ConfigEntityBase::isInstallable public function Checks whether this entity is installable. Overrides ConfigEntityInterface::isInstallable 2
ConfigEntityBase::isNew public function Overrides Entity::isNew(). Overrides EntityBase::isNew
ConfigEntityBase::isUninstalling public function Returns whether this entity is being changed during the uninstall process. Overrides ConfigEntityInterface::isUninstalling
ConfigEntityBase::link public function Deprecated way of generating a link to the entity. See toLink(). Overrides EntityBase::link
ConfigEntityBase::onDependencyRemoval public function Informs the entity that entities it depends on will be deleted. Overrides ConfigEntityInterface::onDependencyRemoval 7
ConfigEntityBase::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. Overrides EntityBase::preDelete 8
ConfigEntityBase::preSave public function Acts on an entity before the presave hook is invoked. Overrides EntityBase::preSave 13
ConfigEntityBase::save public function Saves an entity permanently. Overrides EntityBase::save 1
ConfigEntityBase::set public function Sets the value of a property. Overrides ConfigEntityInterface::set
ConfigEntityBase::setOriginalId public function Sets the original ID. Overrides EntityBase::setOriginalId
ConfigEntityBase::setStatus public function Sets the status of the configuration entity. Overrides ConfigEntityInterface::setStatus
ConfigEntityBase::setThirdPartySetting public function Sets the value of a third-party setting. Overrides ThirdPartySettingsInterface::setThirdPartySetting
ConfigEntityBase::setUninstalling public function
ConfigEntityBase::sort public static function Helper callback for uasort() to sort configuration entities by weight and label. 6
ConfigEntityBase::status public function Returns whether the configuration entity is enabled. Overrides ConfigEntityInterface::status 4
ConfigEntityBase::toArray public function Gets an array of all property values. Overrides EntityBase::toArray 2
ConfigEntityBase::toUrl public function Gets the URL object for the entity. Overrides EntityBase::toUrl
ConfigEntityBase::trustData public function Sets that the data should be trusted. Overrides ConfigEntityInterface::trustData
ConfigEntityBase::unsetThirdPartySetting public function Unsets a third-party setting. Overrides ThirdPartySettingsInterface::unsetThirdPartySetting
ConfigEntityBase::url public function Gets the public URL for this entity. Overrides EntityBase::url
ConfigEntityBase::urlInfo public function Gets the URL object for the entity. Overrides EntityBase::urlInfo
ConfigEntityBase::__construct public function Constructs an Entity object. Overrides EntityBase::__construct 10
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function Aliased as: traitSleep 1
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency. Aliased as: addDependencyTrait
EntityBase::$enforceIsNew protected property Boolean indicating whether the entity should be forced to be new.
EntityBase::$entityTypeId protected property The entity type.
EntityBase::$typedData protected property A typed data object wrapping this entity.
EntityBase::access public function Checks data value access. Overrides AccessibleInterface::access 1
EntityBase::bundle public function Gets the bundle of the entity. Overrides EntityInterface::bundle 1
EntityBase::create public static function Constructs a new entity object, without permanently saving it. Overrides EntityInterface::create
EntityBase::delete public function Deletes an entity permanently. Overrides EntityInterface::delete 2
EntityBase::enforceIsNew public function Enforces an entity to be new. Overrides EntityInterface::enforceIsNew
EntityBase::entityManager Deprecated protected function Gets the entity manager.
EntityBase::entityTypeBundleInfo protected function Gets the entity type bundle info service.
EntityBase::entityTypeManager protected function Gets the entity type manager.
EntityBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
EntityBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
EntityBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyTrait::getCacheTags
EntityBase::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. Overrides EntityInterface::getConfigDependencyKey
EntityBase::getEntityType public function Gets the entity type definition. Overrides EntityInterface::getEntityType
EntityBase::getEntityTypeId public function Gets the ID of the type of the entity. Overrides EntityInterface::getEntityTypeId
EntityBase::getListCacheTagsToInvalidate protected function The list cache tags to invalidate for this entity.
EntityBase::getTypedData public function Gets a typed data object for this entity object. Overrides EntityInterface::getTypedData
EntityBase::hasLinkTemplate public function Indicates if a link template exists for a given key. Overrides EntityInterface::hasLinkTemplate
EntityBase::id public function Gets the identifier. Overrides EntityInterface::id 11
EntityBase::label public function Gets the label of the entity. Overrides EntityInterface::label 6
EntityBase::language public function Gets the language of the entity. Overrides EntityInterface::language 1
EntityBase::languageManager protected function Gets the language manager.
EntityBase::linkTemplates protected function Gets an array link templates. 1
EntityBase::load public static function Loads an entity. Overrides EntityInterface::load
EntityBase::loadMultiple public static function Loads one or more entities. Overrides EntityInterface::loadMultiple
EntityBase::postCreate public function Acts on a created entity before hooks are invoked. Overrides EntityInterface::postCreate 4
EntityBase::postLoad public static function Acts on loaded entities. Overrides EntityInterface::postLoad 2
EntityBase::preCreate public static function Changes the values of an entity before it is created. Overrides EntityInterface::preCreate 5
EntityBase::referencedEntities public function Gets a list of entities referenced by this entity. Overrides EntityInterface::referencedEntities 1
EntityBase::toLink public function Generates the HTML for a link to this entity. Overrides EntityInterface::toLink
EntityBase::uriRelationships public function Gets a list of URI relationships supported by this entity. Overrides EntityInterface::uriRelationships
EntityBase::urlRouteParameters protected function Gets an array of placeholders for this entity. 2
EntityBase::uuid public function Gets the entity UUID (Universally Unique Identifier). Overrides EntityInterface::uuid 1
EntityBase::uuidGenerator protected function Gets the UUID generator.
Facet::$active_values protected property An array of active values.
Facet::$description protected property A string describing the facet.
Facet::$empty_behavior protected property The no-result configuration.
Facet::$enable_parent_when_child_gets_disabled protected property Wether or not parents should be enabled when a child gets disabled.
Facet::$exclude protected property A boolean flag indicating if search should exclude selected facets.
Facet::$expand_hierarchy protected property A boolean indicating if hierarchical items should always be expanded.
Facet::$facetSourceConfig protected property The facet source config object.
Facet::$facetSourcePlugins protected property An array containing the facet source plugins.
Facet::$facet_source_id protected property The id of the facet source.
Facet::$facet_source_instance protected property The facet source belonging to this facet.
Facet::$field_identifier protected property The field identifier.
Facet::$hard_limit protected property Hard limit for the facet items.
Facet::$hierarchy protected property The hierarchy definition.
Facet::$hierarchy_manager protected property The hierarchy plugin manager.
Facet::$hierarchy_processor protected property The hierarchy instance.
Facet::$id protected property The ID of the facet.
Facet::$keep_hierarchy_parents_active protected property A boolean flag indicating if the parent results of a hierarchical facet should be kept active when a child becomes active.
Facet::$min_count protected property The minimum amount of results to show.
Facet::$name protected property A name to be displayed for the facet.
Facet::$only_visible_when_facet_source_is_visible protected property Is the facet only visible when the facet source is only visible.
Facet::$path protected property The path all the links should point to.
Facet::$processors protected property Cached information about the processors available for this facet.
Facet::$processor_configs protected property Configuration for the processors. This is an array of arrays.
Facet::$query_operator protected property The operator to hand over to the query, currently AND | OR.
Facet::$results protected property The results.
Facet::$show_only_one_result protected property Determines if only one result can be selected in the facet at one time.
Facet::$url_alias protected property The name for the parameter when used in the URL.
Facet::$use_hierarchy protected property A boolean flag indicating if search should exclude selected facets.
Facet::$weight protected property The facet weight.
Facet::$widget protected property The widget plugin definition.
Facet::$widgetInstance protected property The widget plugin instance.
Facet::$widget_plugin_manager protected property The widget plugin manager.
Facet::addProcessor public function Adds a processor for this facet. Overrides FacetInterface::addProcessor
Facet::calculateDependencies public function Calculates dependencies and stores them in the dependency property. Overrides ConfigEntityBase::calculateDependencies
Facet::clearBlockCache protected static function Clear the block cache.
Facet::getActiveItems public function Returns all the active items in the facet. Overrides FacetInterface::getActiveItems
Facet::getDataDefinition public function Returns the data definition from the facet field. Overrides FacetInterface::getDataDefinition
Facet::getDescription public function
Facet::getEmptyBehavior public function Returns the defined no-results behavior or NULL if none defined. Overrides FacetInterface::getEmptyBehavior
Facet::getEnableParentWhenChildGetsDisabled public function Returns the value of the enable_parent_when_child_gets_disabled boolean. Overrides FacetInterface::getEnableParentWhenChildGetsDisabled
Facet::getExclude public function Returns the value of the exclude boolean. Overrides FacetInterface::getExclude
Facet::getExpandHierarchy public function Returns the value of the expand_hierarchy boolean. Overrides FacetInterface::getExpandHierarchy
Facet::getFacetSource public function Returns the plugin instance of a facet source. Overrides FacetInterface::getFacetSource
Facet::getFacetSourceConfig public function Returns the facet source configuration object. Overrides FacetInterface::getFacetSourceConfig
Facet::getFacetSourceId public function Returns the Facet source id. Overrides FacetInterface::getFacetSourceId
Facet::getFacetSources public function Loads the facet sources for this facet. Overrides FacetInterface::getFacetSources
Facet::getFieldAlias public function Returns the field alias used to identify the facet in the url. Overrides FacetInterface::getFieldAlias
Facet::getFieldIdentifier public function Returns field identifier. Overrides FacetInterface::getFieldIdentifier
Facet::getHardLimit public function Returns the limit number for facet items. Overrides FacetInterface::getHardLimit
Facet::getHierarchy public function Returns the facet hierarchy definition. Overrides FacetInterface::getHierarchy
Facet::getHierarchyInstance public function Returns the facet hierarchy instance. Overrides FacetInterface::getHierarchyInstance
Facet::getHierarchyManager public function Returns the hierarchy plugin manager.
Facet::getKeepHierarchyParentsActive public function Returns the value of the keep_hierarchy_parents_active boolean. Overrides FacetInterface::getKeepHierarchyParentsActive
Facet::getMinCount public function Returns the minimum count of the result to show. Overrides FacetInterface::getMinCount
Facet::getName public function Returns the field name of the facet as used in the index. Overrides FacetInterface::getName
Facet::getOnlyVisibleWhenFacetSourceIsVisible public function Returns the "only visible when facet source is visible" boolean flag. Overrides FacetInterface::getOnlyVisibleWhenFacetSourceIsVisible
Facet::getProcessorConfigs public function Retrieves this facets's processor configs. Overrides FacetInterface::getProcessorConfigs
Facet::getProcessors public function Returns an array of processors with their configuration. Overrides FacetInterface::getProcessors
Facet::getProcessorsByStage public function Loads this facets processors for a specific stage. Overrides FacetInterface::getProcessorsByStage
Facet::getQueryOperator public function Returns the query operator. Overrides FacetInterface::getQueryOperator
Facet::getQueryType public function Returns the query type instance. Overrides FacetInterface::getQueryType
Facet::getResults public function Returns the result for the facet. Overrides FacetInterface::getResults
Facet::getShowOnlyOneResult public function Returns the show_only_one_result option. Overrides FacetInterface::getShowOnlyOneResult
Facet::getUrlAlias public function Returns the name of the facet for use in the URL. Overrides FacetInterface::getUrlAlias
Facet::getUseHierarchy public function Returns the value of the use_hierarchy boolean. Overrides FacetInterface::getUseHierarchy
Facet::getWeight public function Returns the weight of the facet. Overrides FacetInterface::getWeight
Facet::getWidget public function Returns the facet widget definition. Overrides FacetInterface::getWidget
Facet::getWidgetInstance public function Returns the facet widget instance. Overrides FacetInterface::getWidgetInstance
Facet::getWidgetManager public function Returns the widget plugin manager.
Facet::isActiveValue public function Checks if a value is active. Overrides FacetInterface::isActiveValue
Facet::loadProcessors protected function Retrieves all processors supported by this facet.
Facet::pickQueryType protected function Choose the query type.
Facet::postDelete public static function Acts on deleted entities before the delete hook is invoked. Overrides EntityBase::postDelete
Facet::postSave public function Acts on a saved entity before the insert or update hook is invoked. Overrides EntityBase::postSave
Facet::removeProcessor public function Removes a processor for this facet. Overrides FacetInterface::removeProcessor
Facet::setActiveItem public function Sets an item with value to active. Overrides FacetInterface::setActiveItem
Facet::setActiveItems public function Overwrites the active items. Overrides FacetInterface::setActiveItems
Facet::setEmptyBehavior public function Defines the no-results behavior. Overrides FacetInterface::setEmptyBehavior
Facet::setEnableParentWhenChildGetsDisabled public function Sets the enable_parent_when_child_gets_disabled. Overrides FacetInterface::setEnableParentWhenChildGetsDisabled
Facet::setExclude public function Sets the exclude. Overrides FacetInterface::setExclude
Facet::setExpandHierarchy public function Sets the expand_hierarchy. Overrides FacetInterface::setExpandHierarchy
Facet::setFacetSourceId public function Sets a string representation of the Facet source plugin. Overrides FacetInterface::setFacetSourceId
Facet::setFieldIdentifier public function Sets field identifier. Overrides FacetInterface::setFieldIdentifier
Facet::setHardLimit public function Sets the hard limit of facet items. Overrides FacetInterface::setHardLimit
Facet::setHierarchy public function Sets the facet hierarchy definition. Overrides FacetInterface::setHierarchy
Facet::setKeepHierarchyParentsActive public function Sets the keep_hierarchy_parents_active. Overrides FacetInterface::setKeepHierarchyParentsActive
Facet::setMinCount public function Sets the minimum count of the result to show. Overrides FacetInterface::setMinCount
Facet::setOnlyVisibleWhenFacetSourceIsVisible public function Sets the "only visible when facet source is visible" boolean flag. Overrides FacetInterface::setOnlyVisibleWhenFacetSourceIsVisible
Facet::setQueryOperator public function Sets the query operator. Overrides FacetInterface::setQueryOperator
Facet::setResults public function Sets the results for the facet. Overrides FacetInterface::setResults
Facet::setShowOnlyOneResult public function Sets the show_only_one_result option. Overrides FacetInterface::setShowOnlyOneResult
Facet::setUrlAlias public function Sets the name of the facet for use in the URL. Overrides FacetInterface::setUrlAlias
Facet::setUseHierarchy public function Sets the use_hierarchy. Overrides FacetInterface::setUseHierarchy
Facet::setWeight public function Sets the weight of the facet. Overrides FacetInterface::setWeight
Facet::setWidget public function Sets the facet widget definition. Overrides FacetInterface::setWidget
Facet::__sleep public function Remove the facet lazy built data when the facet is serialized. Overrides ConfigEntityBase::__sleep
PluginDependencyTrait::calculatePluginDependencies protected function Calculates and adds dependencies of a specific plugin instance. 1
PluginDependencyTrait::getPluginDependencies protected function Calculates and returns dependencies of a specific plugin instance.
PluginDependencyTrait::moduleHandler protected function Wraps the module handler. 1
PluginDependencyTrait::themeHandler protected function Wraps the theme handler. 1
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
SynchronizableEntityTrait::$isSyncing protected property Whether this entity is being created, updated or deleted through a synchronization process.
SynchronizableEntityTrait::isSyncing public function
SynchronizableEntityTrait::setSyncing public function