LibraryDiscoveryParser::setOverrideValue

protected LibraryDiscoveryParser::setOverrideValue(array &$library, array $sub_key, array $overrides, $theme_path)

Overrides the specified library asset.

Parameters

array $library: The containing library definition.

array $sub_key: An array containing the sub-keys specifying the library asset, e.g.

php['js']

or

php['css', 'component']

array $overrides: Specifies the overrides, this is an array where the key is the asset to be overridden while the value is overriding asset.

File

core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php, line 419

Class

LibraryDiscoveryParser
Parses library files to get extension data.

Namespace

Drupal\Core\Asset

Code

protected function setOverrideValue(array &$library, array $sub_key, array $overrides, $theme_path) {
  foreach ($overrides as $original => $replacement) {
    // Get the attributes of the asset to be overridden. If the key does
    // not exist, then throw an exception.
    $key_exists = NULL;
    $parents = array_merge($sub_key, [$original]);
    // Save the attributes of the library asset to be overridden.
    $attributes = NestedArray::getValue($library, $parents, $key_exists);
    if ($key_exists) {
      // Remove asset to be overridden.
      NestedArray::unsetValue($library, $parents);
      // No need to replace if FALSE is specified, since that is a removal.
      if ($replacement) {
        // Ensure the replacement path is relative to drupal root.
        $replacement = $this->resolveThemeAssetPath($theme_path, $replacement);
        $new_parents = array_merge($sub_key, [$replacement]);
        // Replace with an override if specified.
        NestedArray::setValue($library, $new_parents, $attributes);
      }
    }
  }
}
doc_Drupal
2016-10-29 09:23:12
Comments
Leave a Comment

Please login to continue.