abstract class FacetSourceDeriverBase in Facets 8
A base class for facet source derivers.
Hierarchy
- class \Drupal\facets\FacetSource\FacetSourceDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of FacetSourceDeriverBase
1 file declares its use of FacetSourceDeriverBase
- SearchApiDisplayDeriver.php in src/
Plugin/ facets/ facet_source/ SearchApiDisplayDeriver.php
File
- src/
FacetSource/ FacetSourceDeriverBase.php, line 14
Namespace
Drupal\facets\FacetSourceView source
abstract class FacetSourceDeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* List of derivative definitions.
*
* @var array
*/
protected $derivatives = [];
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The search api display plugin manager.
*
* @var \Drupal\search_api\Display\DisplayPluginManager
*/
protected $searchApiDisplayPluginManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
$deriver = new static();
$module_list = $container
->get('module_handler')
->getModuleList();
if (!in_array('search_api', array_keys($module_list))) {
return;
}
$entity_type_manager = $container
->get('entity_type.manager');
$deriver
->setEntityTypeManager($entity_type_manager);
$translation = $container
->get('string_translation');
$deriver
->setStringTranslation($translation);
$search_api_display_plugin_manager = $container
->get('plugin.manager.search_api.display');
$deriver
->setSearchApiDisplayPluginManager($search_api_display_plugin_manager);
return $deriver;
}
/**
* Retrieves the entity manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity manager.
*/
public function getEntityTypeManager() {
return $this->entityTypeManager ?: \Drupal::service('entity_type.manager');
}
/**
* Sets the entity manager.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
*
* @return $this
*/
public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
return $this;
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
$derivatives = $this
->getDerivativeDefinitions($base_plugin_definition);
return isset($derivatives[$derivative_id]) ? $derivatives[$derivative_id] : NULL;
}
/**
* Sets search api's display plugin manager.
*
* @param \Drupal\search_api\Display\DisplayPluginManager $search_api_display_plugin_manager
* The plugin manager.
*/
public function setSearchApiDisplayPluginManager(DisplayPluginManager $search_api_display_plugin_manager) {
$this->searchApiDisplayPluginManager = $search_api_display_plugin_manager;
}
/**
* Returns the display plugin manager.
*
* @return \Drupal\search_api\Display\DisplayPluginManager
* The plugin manager.
*/
public function getSearchApiDisplayPluginManager() {
return $this->searchApiDisplayPluginManager;
}
/**
* Compares two plugin definitions according to their labels.
*
* @param array $a
* A plugin definition, with at least a "label" key.
* @param array $b
* Another plugin definition.
*
* @return int
* An integer less than, equal to, or greater than zero if the first
* argument is considered to be respectively less than, equal to, or greater
* than the second.
*/
public function compareDerivatives(array $a, array $b) {
return strnatcasecmp($a['label'], $b['label']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverInterface:: |
public | function | Gets the definition of all derivatives of a base plugin. | 14 |
FacetSourceDeriverBase:: |
protected | property | List of derivative definitions. | |
FacetSourceDeriverBase:: |
protected | property | The entity manager. | |
FacetSourceDeriverBase:: |
protected | property | The search api display plugin manager. | |
FacetSourceDeriverBase:: |
public | function | Compares two plugin definitions according to their labels. | |
FacetSourceDeriverBase:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
FacetSourceDeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
FacetSourceDeriverBase:: |
public | function | Retrieves the entity manager. | |
FacetSourceDeriverBase:: |
public | function | Returns the display plugin manager. | |
FacetSourceDeriverBase:: |
public | function | Sets the entity manager. | |
FacetSourceDeriverBase:: |
public | function | Sets search api's display plugin manager. | |
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. |