You are here

protected function LibraryPolicyBuilder::getExtensionSources in Content-Security-Policy 8

Get the required sources for an extension.

Parameters

string $extension: The name of the extension that registered a library.

Return value

array An array of sources keyed by type.

1 call to LibraryPolicyBuilder::getExtensionSources()
LibraryPolicyBuilder::getSources in src/LibraryPolicyBuilder.php
Retrieve all sources required for the active theme.

File

src/LibraryPolicyBuilder.php, line 132

Class

LibraryPolicyBuilder
Service to build policy information for libraries.

Namespace

Drupal\csp

Code

protected function getExtensionSources($extension) {
  $cid = implode(':', [
    'csp',
    'extension',
    $extension,
  ]);
  $cacheItem = $this->cache
    ->get($cid);
  if ($cacheItem) {
    return $cacheItem->data;
  }
  $sources = [];
  $moduleLibraries = $this->libraryDiscovery
    ->getLibrariesByExtension($extension);
  foreach ($moduleLibraries as $libraryName => $libraryInfo) {
    $librarySources = $this
      ->getLibrarySources($extension, $libraryName);
    $sources = NestedArray::mergeDeep($sources, $librarySources);
  }
  $this->cache
    ->set($cid, $sources, Cache::PERMANENT, [
    'library_info',
  ]);
  return $sources;
}