You are here

protected function StableLibraryOverrideTest::removeVendorAssets in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Theme/StableLibraryOverrideTest.php \Drupal\KernelTests\Core\Theme\StableLibraryOverrideTest::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, and so on.

Return value

array[] The reduced array of libraries.

1 call to StableLibraryOverrideTest::removeVendorAssets()
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/StableLibraryOverrideTest.php, line 139

Class

StableLibraryOverrideTest
Tests Stable's library overrides.

Namespace

Drupal\KernelTests\Core\Theme

Code

protected function removeVendorAssets($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;
}