function LibraryDiscoveryParser::librariesForComponents

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php \Drupal\Core\Asset\LibraryDiscoveryParser::librariesForComponents()

Builds the dynamic library definitions for single-directory components.

Return value

array The core library definitions for Single-Directory Components.

1 call to LibraryDiscoveryParser::librariesForComponents()
LibraryDiscoveryParser::parseLibraryInfo in core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php
Parses a given library file and allows modules and themes to alter it.

File

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

Class

LibraryDiscoveryParser
Parses library files to get extension data.

Namespace

Drupal\Core\Asset

Code

protected function librariesForComponents() : array {
  // Iterate over all the components to get the CSS and JS files.
  $components = $this->componentPluginManager
    ->getAllComponents();
  $libraries = array_reduce($components, static function (array $libraries, Component $component) {
    $library = $component->library;
    if (empty($library)) {
      return $libraries;
    }
    $library_name = $component->getLibraryName();
    [
      ,
      $library_id,
    ] = explode('/', $library_name);
    return array_merge($libraries, [
      $library_id => $library,
    ]);
  }, []);
  $libraries['components.all'] = [
    'dependencies' => array_map(static fn(Component $component) => $component->getLibraryName(), $components),
  ];
  return $libraries;
}

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