class EntityHierarchySelectionDeriver in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x src/Plugin/Derivative/EntityHierarchySelectionDeriver.php \Drupal\entity_hierarchy\Plugin\Derivative\EntityHierarchySelectionDeriver
Derives an entity reference selection handler for each entity type.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\entity_hierarchy\Plugin\Derivative\EntityHierarchySelectionDeriver implements ContainerDeriverInterface
Expanded class hierarchy of EntityHierarchySelectionDeriver
File
- src/
Plugin/ Derivative/ EntityHierarchySelectionDeriver.php, line 13
Namespace
Drupal\entity_hierarchy\Plugin\DerivativeView source
class EntityHierarchySelectionDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* Entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Creates an EntityHierarchySelectionDeriverobject.
*
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* Entity field manager.
*/
public function __construct(EntityFieldManagerInterface $entityFieldManager) {
$this->entityFieldManager = $entityFieldManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityFieldManager
->getFieldMapByFieldType('entity_reference_hierarchy') as $entity_type_id => $info) {
foreach ($info as $field_name => $bundles) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $sample_field */
$fields = $this->entityFieldManager
->getFieldDefinitions($entity_type_id, reset($bundles['bundles']));
$sample_field_name = $field_name;
if (isset($fields[$field_name])) {
$sample_field_name = $fields[$field_name]
->getName();
}
$key = $entity_type_id;
$this->derivatives[$key] = $base_plugin_definition;
$this->derivatives[$key]['entity_types'] = [
$entity_type_id,
];
$this->derivatives[$key]['field_name'] = $field_name;
$this->derivatives[$key]['label'] = t('Selection with hierarchy (@field_name)', [
'@field_name' => $sample_field_name,
]);
$this->derivatives[$key]['base_plugin_label'] = (string) $base_plugin_definition['label'];
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
EntityHierarchySelectionDeriver:: |
protected | property | Entity field manager. | |
EntityHierarchySelectionDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
EntityHierarchySelectionDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
EntityHierarchySelectionDeriver:: |
public | function | Creates an EntityHierarchySelectionDeriverobject. |