You are here

public function LibraryDeriver::getPatterns in UI Patterns 8

Get pattern definition objects.

Return value

\Drupal\ui_patterns\Definition\PatternDefinition[] List of pattern definitions contained in the file.

Overrides PatternsDeriverInterface::getPatterns

File

modules/ui_patterns_library/src/Plugin/Deriver/LibraryDeriver.php, line 133

Class

LibraryDeriver
Class LibraryDeriver.

Namespace

Drupal\ui_patterns_library\Plugin\Deriver

Code

public function getPatterns() {
  $patterns = [];
  foreach ($this
    ->getDirectories() as $provider => $directory) {
    foreach ($this
      ->fileScanDirectory($directory) as $file_path => $file) {
      $host_extension = $this
        ->getHostExtension($file_path);
      if ($host_extension == FALSE || $host_extension == $provider) {
        $content = file_get_contents($file_path);
        foreach (Yaml::decode($content) as $id => $definition) {
          $definition['id'] = $id;
          $definition['base path'] = dirname($file_path);
          $definition['file name'] = basename($file_path);
          $definition['provider'] = $provider;
          $patterns[] = $this
            ->getPatternDefinition($definition);
        }
      }
    }
  }
  return $patterns;
}