class DynamicLayoutDeriver in Dynamic Layouts 8
Makes a flexible layout for each layout config entity.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\dynamic_layouts\Plugin\Derivative\DynamicLayoutDeriver implements ContainerDeriverInterface
Expanded class hierarchy of DynamicLayoutDeriver
File
- src/
Plugin/ Derivative/ DynamicLayoutDeriver.php, line 14
Namespace
Drupal\dynamic_layouts\Plugin\DerivativeView source
class DynamicLayoutDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The base plugin ID that the derivative is for.
*
* @var string
*/
protected $basePluginId;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* DynamicLayoutDeriver constructor.
*
* @param string $base_plugin_id
* The base plugin ID.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct($base_plugin_id, EntityTypeManagerInterface $entityTypeManager) {
$this->basePluginId = $base_plugin_id;
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$config_entities = $this->entityTypeManager
->getStorage('dynamic_layout')
->loadMultiple();
// Now we loop over them and declare the derivatives.
if ($config_entities) {
foreach ($config_entities as $entity) {
/* @var \Drupal\dynamic_layouts\DynamicLayoutInterface $entity */
$regions = $entity
->getLayoutRegions();
$icon_map = $entity
->getIconMap();
$module_path = drupal_get_path('module', 'dynamic_layouts') . '/templates';
$this->derivatives[$entity
->id()] = new LayoutDefinition([
'label' => $entity
->label(),
'category' => $entity
->getCategory(),
'class' => 'Drupal\\dynamic_layouts\\Plugin\\Layout\\DynamicLayout',
'regions' => $regions,
'template' => 'dynamic-layout-frontend',
'path' => $module_path,
'icon_map' => $icon_map,
'config_dependencies' => [
$entity
->getConfigDependencyKey() => [
$entity
->getConfigDependencyName(),
],
],
]);
}
}
return $this->derivatives;
}
}
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:: |
|
DynamicLayoutDeriver:: |
protected | property | The base plugin ID that the derivative is for. | |
DynamicLayoutDeriver:: |
protected | property | The entity type manager. | |
DynamicLayoutDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
DynamicLayoutDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
DynamicLayoutDeriver:: |
public | function | DynamicLayoutDeriver constructor. |