public function EntityHierarchySelectionDeriver::getDerivativeDefinitions in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/Derivative/EntityHierarchySelectionDeriver.php \Drupal\entity_hierarchy\Plugin\Derivative\EntityHierarchySelectionDeriver::getDerivativeDefinitions()
Gets the definition of all derivatives of a base plugin.
Parameters
array $base_plugin_definition: The definition array of the base plugin.
Return value
array An array of full derivative definitions keyed on derivative id.
Overrides DeriverBase::getDerivativeDefinitions
See also
getDerivativeDefinition()
File
- src/
Plugin/ Derivative/ EntityHierarchySelectionDeriver.php, line 44
Class
- EntityHierarchySelectionDeriver
- Derives an entity reference selection handler for each entity type.
Namespace
Drupal\entity_hierarchy\Plugin\DerivativeCode
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);
}