You are here

protected function PatternBase::processLibraries in UI Patterns 8

Process libraries.

Parameters

array|string $libraries: List of dependencies or "dependencies:" root property.

string $base_path: Pattern base path.

string $parent: Item parent set in previous recursive iteration, if any.

1 call to PatternBase::processLibraries()
PatternBase::getLibraryDefinitions in src/Plugin/PatternBase.php
Get library definitions for current pattern.

File

src/Plugin/PatternBase.php, line 106

Class

PatternBase
Class PatternBase.

Namespace

Drupal\ui_patterns\Plugin

Code

protected function processLibraries(&$libraries, $base_path, $parent = '') {
  if (!is_string($libraries)) {
    $parents = [
      'js',
      'base',
      'layout',
      'component',
      'state',
      'theme',
    ];
    $_libraries = $libraries;
    foreach ($_libraries as $name => $values) {
      $is_asset = in_array($parent, $parents, TRUE);
      $is_external = isset($values['type']) && $values['type'] == 'external';
      if ($is_asset && !$is_external) {
        $libraries[$base_path . DIRECTORY_SEPARATOR . $name] = $values;
        unset($libraries[$name]);
      }
      elseif (!$is_asset) {
        $this
          ->processLibraries($libraries[$name], $base_path, $name);
      }
    }
  }
}