LibraryDiscoveryCollector::applyLibrariesExtend

protected LibraryDiscoveryCollector::applyLibrariesExtend($extension, $library_name, $library_definition)

Applies the libraries-extend specified by the active theme.

This extends the library definitions with the those specified by the libraries-extend specifications for the active theme.

Parameters

string $extension: The name of the extension for which library definitions will be extended.

string $library_name: The name of the library whose definitions is to be extended.

$library_definition: The library definition to be extended.

Return value

array The library definition extended as specified by libraries-extend.

Throws

\Drupal\Core\Asset\Exception\InvalidLibrariesExtendSpecificationException

File

core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php, line 135

Class

LibraryDiscoveryCollector
A CacheCollector implementation for building library extension info.

Namespace

Drupal\Core\Asset

Code

protected function applyLibrariesExtend($extension, $library_name, $library_definition) {
  $libraries_extend = $this->themeManager->getActiveTheme()->getLibrariesExtend();
  if (!empty($libraries_extend["$extension/$library_name"])) {
    foreach ($libraries_extend["$extension/$library_name"] as $library_extend_name) {
      if (!is_string($library_extend_name)) {
        // Only string library names are allowed.
        throw new InvalidLibrariesExtendSpecificationException('The libraries-extend specification for each library must be a list of strings.');
      }
      list($new_extension, $new_library_name) = explode('/', $library_extend_name, 2);
      $new_libraries = $this->get($new_extension);
      if (isset($new_libraries[$new_library_name])) {
        $library_definition = NestedArray::mergeDeep($library_definition, $new_libraries[$new_library_name]);
      }
      else {
        throw new InvalidLibrariesExtendSpecificationException(sprintf('The specified library "%s" does not exist.', $library_extend_name));
      }
    }
  }
  return $library_definition;
}
doc_Drupal
2016-10-29 09:23:08
Comments
Leave a Comment

Please login to continue.