You are here

protected function Stable9LibraryOverrideTest::removeVendorAssets in Drupal 9

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, and so on.

Return value

array[] The reduced array of libraries.

1 call to Stable9LibraryOverrideTest::removeVendorAssets()
Stable9LibraryOverrideTest::testStable9LibraryOverrides in core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php
Ensures that Stable 9 overrides all relevant core library assets.

File

core/tests/Drupal/KernelTests/Core/Theme/Stable9LibraryOverrideTest.php, line 146

Class

Stable9LibraryOverrideTest
Tests Stable 9's library overrides.

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;
}