public function ComponentBlockBlockDeriver::getDerivativeDefinitions in Component blocks 1.0.x
Same name and namespace in other branches
- 1.x src/Plugin/Deriver/ComponentBlockBlockDeriver.php \Drupal\component_blocks\Plugin\Deriver\ComponentBlockBlockDeriver::getDerivativeDefinitions()
- 1.1.x src/Plugin/Deriver/ComponentBlockBlockDeriver.php \Drupal\component_blocks\Plugin\Deriver\ComponentBlockBlockDeriver::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/ Deriver/ ComponentBlockBlockDeriver.php, line 49
Class
- ComponentBlockBlockDeriver
- Defines a class for deriving blocks from component block plugins.
Namespace
Drupal\component_blocks\Plugin\DeriverCode
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->pluginManager
->getDefinitions() as $id => $definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_definition) {
// We have to loop per content entity for the correct context.
if (!$entity_type_definition
->entityClassImplements(ContentEntityInterface::class)) {
continue;
}
$entity_type_id = $entity_type_definition
->id();
$entity_type_label = $entity_type_definition
->getLabel();
$context_definition = EntityContextDefinition::fromEntityTypeId($entity_type_id)
->setLabel($entity_type_label);
$this->derivatives[$entity_type_id . ':' . $id] = [
'admin_label' => new TranslatableMarkup('@component with fields from @entity', [
'@component' => $definition['label'],
'@entity' => $entity_type_label,
]),
// These are inherently bound to layout builder.
'_block_ui_hidden' => TRUE,
'ui_pattern_id' => $id,
'context_definitions' => [
'entity' => $context_definition,
],
] + $base_plugin_definition;
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}