function StableLibraryOverrideTestBase::removeVendorAssets

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php \Drupal\KernelTests\Core\Theme\StableLibraryOverrideTestBase::removeVendorAssets()
  2. 11.x core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php \Drupal\KernelTests\Core\Theme\StableLibraryOverrideTestBase::removeVendorAssets()

Removes all vendor libraries and assets from the library definitions.

Parameters

array[] $all_libraries: An associative array of libraries keyed by extension, then by library name, then by asset type.

Return value

array[] The reduced array of libraries.

2 calls to StableLibraryOverrideTestBase::removeVendorAssets()
Stable9LibraryOverrideTest::testStable9LibraryOverrides in core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php
Ensures that Stable 9 overrides all relevant core library assets.
StableLibraryOverrideTest::testStableLibraryOverrides in core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTest.php
Ensures that Stable overrides all relevant core library assets.

File

core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTestBase.php, line 93

Class

StableLibraryOverrideTestBase
Tests the behavior of a theme when base_theme info key is missing.

Namespace

Drupal\KernelTests\Core\Theme

Code

protected function removeVendorAssets(array $all_libraries) {
    foreach ($all_libraries as $extension => $libraries) {
        foreach ($libraries as $library_name => $library) {
            if (isset($library['remote'])) {
                unset($all_libraries[$extension][$library_name]);
            }
            foreach ([
                'css',
                'js',
            ] as $asset_type) {
                foreach ($library[$asset_type] as $index => $asset) {
                    if (strpos($asset['data'], 'core/assets/vendor') !== FALSE) {
                        unset($all_libraries[$extension][$library_name][$asset_type][$index]);
                        // Re-key the array of assets. This is needed because
                        // libraries-override doesn't always preserve the order.
                        if (!empty($all_libraries[$extension][$library_name][$asset_type])) {
                            $all_libraries[$extension][$library_name][$asset_type] = array_values($all_libraries[$extension][$library_name][$asset_type]);
                        }
                    }
                }
            }
        }
    }
    return $all_libraries;
}

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