protected function Layout::iterateDirectories

Finds layout definitions by looking for layout metadata.

1 call to Layout::iterateDirectories()
Layout::getDerivativeDefinitions in drupal/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php
Implements DerivativeInterface::getDerivativeDefinitions().

File

drupal/core/modules/layout/lib/Drupal/layout/Plugin/Derivative/Layout.php, line 93
Definition of Drupal\layout\Plugin\Derivative\Layout.

Class

Layout
Layout plugin derivative definition.

Namespace

Drupal\layout\Plugin\Derivative

Code

protected function iterateDirectories($dir, $provider) {
  $directories = new DirectoryIterator($dir);
  foreach ($directories as $fileinfo) {
    if ($fileinfo
      ->isDir() && !$fileinfo
      ->isDot()) {

      // Keep discovering in subdirectories to arbitrary depth.
      $this
        ->iterateDirectories($fileinfo
        ->getPathname(), $provider);
    }
    elseif ($fileinfo
      ->isFile() && pathinfo($fileinfo
      ->getFilename(), PATHINFO_EXTENSION) == 'yml') {

      // Declarative layout definitions are defined with a .yml file in a
      // layout subdirectory. This provides all information about the layout
      // such as layout markup template and CSS and JavaScript files to use.
      $directory = new FileStorage($fileinfo
        ->getPath());
      $key = $provider['provider'] . '__' . $fileinfo
        ->getBasename('.yml');
      $this->derivatives[$key] = $directory
        ->read($fileinfo
        ->getBasename('.yml'));
      $this->derivatives[$key]['theme'] = $key;
      $this->derivatives[$key]['path'] = $fileinfo
        ->getPath();
      $this->derivatives[$key]['provider'] = $provider;

      // If the layout author didn't specify a template name, assume the same
      // name as the yml file.
      if (!isset($this->derivatives[$key]['template'])) {
        $this->derivatives[$key]['template'] = $fileinfo
          ->getBasename('.yml');
      }
    }
  }
}