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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\facets\FacetSource\FacetSourcePluginBase implements ContainerFactoryPluginInterface, FacetSourcePluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FacetSourcePluginBase
See also
\Drupal\facets\Annotation\FacetsFacetSource
\Drupal\facets\FacetSource\FacetSourcePluginManager
\Drupal\facets\FacetSource\FacetSourcePluginInterface
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\FacetSourceView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DependentPluginInterface:: |
public | function | Calculates dependencies for the configured plugin. | 19 |
FacetSourcePluginBase:: |
protected | property | The facet we're editing for. | |
FacetSourcePluginBase:: |
protected | property | The search keys, or query text, submitted by the user. | |
FacetSourcePluginBase:: |
protected | property | The plugin manager. | |
FacetSourcePluginBase:: |
public | function |
Builds and returns an extra renderable array for this facet block plugin. Overrides FacetSourcePluginInterface:: |
1 |
FacetSourcePluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
FacetSourcePluginBase:: |
public | function |
Returns the number of results that were found for this search. Overrides FacetSourcePluginInterface:: |
1 |
FacetSourcePluginBase:: |
public | function |
Returns an array of fields that are defined on the facet source. Overrides FacetSourcePluginInterface:: |
2 |
FacetSourcePluginBase:: |
public | function |
Returns the allowed query types for a given facet for the facet source. Overrides FacetSourcePluginInterface:: |
2 |
FacetSourcePluginBase:: |
public | function |
Returns the search keys, or query text, submitted by the user. Overrides FacetSourcePluginInterface:: |
|
FacetSourcePluginBase:: |
public | function |
Returns true if the Facet source is being rendered in the current request. Overrides FacetSourcePluginInterface:: |
1 |
FacetSourcePluginBase:: |
public | function |
Sets the search keys, or query text, submitted by the user. Overrides FacetSourcePluginInterface:: |
|
FacetSourcePluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
FacetSourcePluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
FacetSourcePluginBase:: |
public | function |
Constructs a FacetSourcePluginBase object. Overrides PluginBase:: |
2 |
FacetSourcePluginInterface:: |
public | function | Fills the facet entities with results from the facet source. | 1 |
FacetSourcePluginInterface:: |
public | function | Returns a single field's data definition from the facet source. | 1 |
FacetSourcePluginInterface:: |
public | function | Returns the path of the facet source, used to build the facet url. | 1 |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginFormInterface:: |
public | function | Form constructor. | 36 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |