class ComponentBlockBlockDeriver in Component blocks 1.1.x
Same name and namespace in other branches
- 1.x src/Plugin/Deriver/ComponentBlockBlockDeriver.php \Drupal\component_blocks\Plugin\Deriver\ComponentBlockBlockDeriver
- 1.0.x src/Plugin/Deriver/ComponentBlockBlockDeriver.php \Drupal\component_blocks\Plugin\Deriver\ComponentBlockBlockDeriver
Defines a class for deriving blocks from component block plugins.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\component_blocks\Plugin\Deriver\ComponentBlockBlockDeriver implements ContainerDeriverInterface
Expanded class hierarchy of ComponentBlockBlockDeriver
File
- src/
Plugin/ Deriver/ ComponentBlockBlockDeriver.php, line 17
Namespace
Drupal\component_blocks\Plugin\DeriverView source
class ComponentBlockBlockDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* Plugin manager.
*
* @var \Drupal\ui_patterns\UiPatternsManager
*/
private $pluginManager;
/**
* Entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* Constructs a new ComponentBlockBlockDeriver.
*
* @param \Drupal\ui_patterns\UiPatternsManager $pluginManager
* Plugin manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
*/
public function __construct(UiPatternsManager $pluginManager, EntityTypeManagerInterface $entityTypeManager) {
$this->pluginManager = $pluginManager;
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('plugin.manager.ui_patterns'), $container
->get('entity_type.manager'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ComponentBlockBlockDeriver:: |
private | property | Entity type manager. | |
ComponentBlockBlockDeriver:: |
private | property | Plugin manager. | |
ComponentBlockBlockDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
ComponentBlockBlockDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
ComponentBlockBlockDeriver:: |
public | function | Constructs a new ComponentBlockBlockDeriver. | |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |