function LibraryDiscoveryParser::applyLibrariesMovedOverrides

Same name in other branches
  1. 10 core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::applyLibrariesMovedOverrides()

Apply overrides to files that have moved.

Parameters

array $library: The library definition.

string $library_name: The library name.

string $extension: The extension name.

array $overrides: The library overrides.

Drupal\Core\Theme\ActiveTheme $active_theme: The active theme.

Return value

array The modified library overrides.

1 call to LibraryDiscoveryParser::applyLibrariesMovedOverrides()
LibraryDiscoveryParser::applyLibrariesOverride in core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
Apply libraries overrides specified for the current active theme.

File

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

Class

LibraryDiscoveryParser
Parses library files to get extension data.

Namespace

Drupal\Core\Asset

Code

protected function applyLibrariesMovedOverrides(array $library, string $library_name, string $extension, array $overrides, ActiveTheme $active_theme) : array {
    if (!isset($library['moved_files'])) {
        return $overrides;
    }
    foreach ($library['moved_files'] as $old_library_name => $moved_files) {
        $deprecation_version = $moved_files['deprecation_version'];
        $removed_version = $moved_files['removed_version'];
        $deprecation_link = $moved_files['deprecation_link'];
        if (isset($overrides[$old_library_name]['css']) && isset($moved_files['css'])) {
            foreach ($overrides[$old_library_name]['css'] as $key => $files) {
                foreach ($files as $original => $target) {
                    if (isset($moved_files['css'][$key][$original])) {
                        $new_key = array_key_first($moved_files['css'][$key][$original]);
                        $new_file = $moved_files['css'][$key][$original][$new_key];
                        $theme_name = $active_theme->getName();
                        // phpcs:ignore
                        @trigger_error("Targeting {$old_library_name} {$original} from {$theme_name} library_overrides is deprecated in {$deprecation_version} and will be removed in {$removed_version}. Target {$extension}/{$library_name} {$new_file} instead. See {$deprecation_link}", E_USER_DEPRECATED);
                        $overrides[$extension . '/' . $library_name]['css'][$new_key][$new_file] = $target;
                    }
                }
            }
        }
        if (isset($overrides[$old_library_name]['js']) && isset($moved_files['js'])) {
            foreach ($overrides[$old_library_name]['js'] as $original => $target) {
                if (isset($moved_files['js'][$original])) {
                    $new_file = $moved_files['js'][$original];
                    $theme_name = $active_theme->getName();
                    // phpcs:ignore
                    @trigger_error("Targeting {$old_library_name} {$original} from {$theme_name} library_overrides is deprecated in {$deprecation_version} and will be removed in {$removed_version}. Target {$extension}/{$library_name} {$new_file} instead. See {$deprecation_link}", E_USER_DEPRECATED);
                    $overrides[$extension . '/' . $library_name]['js'][$new_file] = $target;
                }
            }
        }
    }
    return $overrides;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.