You are here

protected function AssetResolver::getJsSettingsAssets in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::getJsSettingsAssets()
  2. 9 core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::getJsSettingsAssets()

Returns the JavaScript settings assets for this response's libraries.

Gathers all drupalSettings from all libraries in the attached assets collection and merges them.

Parameters

\Drupal\Core\Asset\AttachedAssetsInterface $assets: The assets attached to the current response.

Return value

array A (possibly optimized) collection of JavaScript assets.

File

core/lib/Drupal/Core/Asset/AssetResolver.php, line 180

Class

AssetResolver
The default asset resolver.

Namespace

Drupal\Core\Asset

Code

protected function getJsSettingsAssets(AttachedAssetsInterface $assets) {
  $settings = [];
  foreach ($this
    ->getLibrariesToLoad($assets) as $library) {
    [
      $extension,
      $name,
    ] = explode('/', $library, 2);
    $definition = $this->libraryDiscovery
      ->getLibraryByName($extension, $name);
    if (isset($definition['drupalSettings'])) {
      $settings = NestedArray::mergeDeepArray([
        $settings,
        $definition['drupalSettings'],
      ], TRUE);
    }
  }
  return $settings;
}