class ContentEntityDeriver in Search API 8
Derives a datasource plugin definition for every content entity type.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\search_api\Plugin\search_api\datasource\ContentEntityDeriver implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of ContentEntityDeriver
See also
\Drupal\search_api\Plugin\search_api\datasource\ContentEntityDatasource
File
- src/
Plugin/ search_api/ datasource/ ContentEntityDeriver.php, line 17
Namespace
Drupal\search_api\Plugin\search_api\datasourceView source
class ContentEntityDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
protected $derivatives = NULL;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
$deriver = new static();
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $container
->get('entity_type.manager');
$deriver
->setEntityTypeManager($entity_type_manager);
/** @var \Drupal\Core\StringTranslation\TranslationInterface $translation */
$translation = $container
->get('string_translation');
$deriver
->setStringTranslation($translation);
return $deriver;
}
/**
* Retrieves the entity type manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* The entity type manager.
*/
public function getEntityTypeManager() {
return $this->entityTypeManager ?: \Drupal::entityTypeManager();
}
/**
* Sets the entity type manager.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*
* @return $this
*/
public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
return $this;
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
if (!isset($this->derivatives)) {
$plugin_derivatives = [];
foreach ($this
->getEntityTypeManager()
->getDefinitions() as $entity_type => $entity_type_definition) {
// We only support content entity types at the moment, since config
// entities don't implement \Drupal\Core\TypedData\ComplexDataInterface.
if ($entity_type_definition instanceof ContentEntityType) {
$plugin_derivatives[$entity_type] = [
'entity_type' => $entity_type,
'label' => $entity_type_definition
->getLabel(),
'description' => $this
->t('Provides %entity_type entities for indexing and searching.', [
'%entity_type' => $entity_type_definition
->getLabel(),
]),
] + $base_plugin_definition;
}
}
$this->derivatives = $plugin_derivatives;
}
return $this->derivatives;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentEntityDeriver:: |
protected | property |
List of derivative definitions. Overrides DeriverBase:: |
|
ContentEntityDeriver:: |
protected | property | The entity type manager. | |
ContentEntityDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
ContentEntityDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
ContentEntityDeriver:: |
public | function | Retrieves the entity type manager. | |
ContentEntityDeriver:: |
public | function | Sets the entity type manager. | |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
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. |