You are here

public function DynamicLayoutDeriver::getDerivativeDefinitions in Dynamic Layouts 8

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/DynamicLayoutDeriver.php, line 56

Class

DynamicLayoutDeriver
Makes a flexible layout for each layout config entity.

Namespace

Drupal\dynamic_layouts\Plugin\Derivative

Code

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;
}