You are here

public function Layout::getDerivativeDefinitions in Layout 8.2

File

lib/Drupal/layout/Plugin/Derivative/Layout.php, line 38
Definition of Drupal\layout\Plugin\Derivative\Layout.

Class

Layout
Layout plugin derivative definition.

Namespace

Drupal\layout\Plugin\Derivative

Code

public function getDerivativeDefinitions(array $base_plugin_definition) {
  $available_layout_providers = array();

  // Add all modules as possible layout providers.
  // @todo Inject the module handler.
  foreach (\Drupal::moduleHandler()
    ->getModuleList() as $module => $filename) {
    $available_layout_providers[$module] = array(
      'type' => 'module',
      'provider' => $module,
      'dir' => dirname($filename),
    );
  }

  // Add all themes as possible layout providers.
  foreach (list_themes() as $theme_id => $theme) {
    $available_layout_providers[$theme_id] = array(
      'type' => 'theme',
      'provider' => $theme->name,
      'dir' => drupal_get_path('theme', $theme->name),
    );
  }
  foreach ($available_layout_providers as $provider) {

    // Looks for layouts in the 'layout' directory under the module/theme.
    // There could be subdirectories under there with one layout defined
    // in each.
    $dir = $provider['dir'] . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . $this->type;
    if (file_exists($dir)) {
      $this
        ->iterateDirectories($dir, $provider);
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}