You are here

protected function LibraryDiscoveryCollector::applyLibrariesExtend in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php \Drupal\Core\Asset\LibraryDiscoveryCollector::applyLibrariesExtend()
  2. 9 core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php \Drupal\Core\Asset\LibraryDiscoveryCollector::applyLibrariesExtend()

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

1 call to LibraryDiscoveryCollector::applyLibrariesExtend()
LibraryDiscoveryCollector::getLibraryDefinitions in core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php
Returns the library definitions for a given extension.

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 (isset($library_definition['deprecated'])) {
        $extend_message = sprintf('Theme "%s" is extending a deprecated library.', $extension);
        $library_deprecation = str_replace('%library_id%', "{$extension}/{$library_name}", $library_definition['deprecated']);
        @trigger_error("{$extend_message} {$library_deprecation}", E_USER_DEPRECATED);
      }
      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.');
      }
      [
        $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;
}