You are here

abstract class FacetSourcePluginBase in Facets 8

Defines a base class from which other facet sources may extend.

Plugins extending this class need to define a plugin definition array through annotation. The definition includes the following keys:

  • id: The unique, system-wide identifier of the facet source.
  • label: The human-readable name of the facet source, translated.
  • description: A human-readable description for the facet source, translated.

Hierarchy

Expanded class hierarchy of FacetSourcePluginBase

See also

\Drupal\facets\Annotation\FacetsFacetSource

\Drupal\facets\FacetSource\FacetSourcePluginManager

\Drupal\facets\FacetSource\FacetSourcePluginInterface

Plugin API

2 files declare their use of FacetSourcePluginBase
SearchApiBaseFacetSource.php in src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php
SearchApiDisplay.php in src/Plugin/facets/facet_source/SearchApiDisplay.php

File

src/FacetSource/FacetSourcePluginBase.php, line 26

Namespace

Drupal\facets\FacetSource
View source
abstract class FacetSourcePluginBase extends PluginBase implements FacetSourcePluginInterface, ContainerFactoryPluginInterface {

  /**
   * The plugin manager.
   *
   * @var \Drupal\facets\QueryType\QueryTypePluginManager
   */
  protected $queryTypePluginManager;

  /**
   * The search keys, or query text, submitted by the user.
   *
   * @var string
   */
  protected $keys;

  /**
   * The facet we're editing for.
   *
   * @var \Drupal\facets\FacetInterface
   */
  protected $facet;

  /**
   * Constructs a FacetSourcePluginBase object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\facets\QueryType\QueryTypePluginManager $query_type_plugin_manager
   *   The query type plugin manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryTypePluginManager $query_type_plugin_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->queryTypePluginManager = $query_type_plugin_manager;
    if (isset($configuration['facet'])) {
      $this->facet = $configuration['facet'];
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {

    // Insert the plugin manager for query types.
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.manager.facets.query_type'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFields() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getQueryTypesForFacet(FacetInterface $facet) {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function isRenderedInCurrentRequest() {
    return FALSE;
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function buildFacet() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getCount() {
    global $pager_total_items;

    // Exposing a global here. This is pretty ugly but the only way to get the
    // actual results for any kind of query that was done and gets back results.
    // @see core/includes/pager.inc for more information how this works.
    // Rounding as some backend plugins could not give accurate information on
    // the results found.
    // @todo Figure out when it can not be the first one in the list.
    return round($pager_total_items[0]);
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $facet_source_id = $this->facet
      ->getFacetSourceId();
    $field_identifier = $form_state
      ->getValue('facet_source_configs')[$facet_source_id]['field_identifier'];
    $this->facet
      ->setFieldIdentifier($field_identifier);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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 1
DependencySerializationTrait::__wakeup public function 2
DependentPluginInterface::calculateDependencies public function Calculates dependencies for the configured plugin. 19
FacetSourcePluginBase::$facet protected property The facet we're editing for.
FacetSourcePluginBase::$keys protected property The search keys, or query text, submitted by the user.
FacetSourcePluginBase::$queryTypePluginManager protected property The plugin manager.
FacetSourcePluginBase::buildFacet public function Builds and returns an extra renderable array for this facet block plugin. Overrides FacetSourcePluginInterface::buildFacet 1
FacetSourcePluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 2
FacetSourcePluginBase::getCount public function Returns the number of results that were found for this search. Overrides FacetSourcePluginInterface::getCount 1
FacetSourcePluginBase::getFields public function Returns an array of fields that are defined on the facet source. Overrides FacetSourcePluginInterface::getFields 2
FacetSourcePluginBase::getQueryTypesForFacet public function Returns the allowed query types for a given facet for the facet source. Overrides FacetSourcePluginInterface::getQueryTypesForFacet 2
FacetSourcePluginBase::getSearchKeys public function Returns the search keys, or query text, submitted by the user. Overrides FacetSourcePluginInterface::getSearchKeys
FacetSourcePluginBase::isRenderedInCurrentRequest public function Returns true if the Facet source is being rendered in the current request. Overrides FacetSourcePluginInterface::isRenderedInCurrentRequest 1
FacetSourcePluginBase::setSearchKeys public function Sets the search keys, or query text, submitted by the user. Overrides FacetSourcePluginInterface::setSearchKeys
FacetSourcePluginBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
FacetSourcePluginBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
FacetSourcePluginBase::__construct public function Constructs a FacetSourcePluginBase object. Overrides PluginBase::__construct 2
FacetSourcePluginInterface::fillFacetsWithResults public function Fills the facet entities with results from the facet source. 1
FacetSourcePluginInterface::getDataDefinition public function Returns a single field's data definition from the facet source. 1
FacetSourcePluginInterface::getPath public function Returns the path of the facet source, used to build the facet url. 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginFormInterface::buildConfigurationForm public function Form constructor. 36
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.