You are here

public function LibraryPolicyBuilder::getSources in Content-Security-Policy 8

Retrieve all sources required for the active theme.

Return value

array An array of sources keyed by type.

File

src/LibraryPolicyBuilder.php, line 87

Class

LibraryPolicyBuilder
Service to build policy information for libraries.

Namespace

Drupal\csp

Code

public function getSources() {
  $cid = implode(':', [
    'csp',
    'sources',
  ]);
  if ($cacheItem = $this->cache
    ->get($cid)) {
    return $cacheItem->data;
  }
  $extensions = array_merge([
    'core',
  ], array_keys($this->moduleHandler
    ->getModuleList()), array_keys($this->themeHandler
    ->listInfo()));
  $sources = [];
  foreach ($extensions as $extensionName) {
    $extensionSources = $this
      ->getExtensionSources($extensionName);
    $sources = NestedArray::mergeDeep($sources, $extensionSources);
  }
  foreach (array_keys($sources) as $type) {
    sort($sources[$type]);
    $sources[$type] = array_unique($sources[$type]);
  }
  $this->cache
    ->set($cid, $sources, Cache::PERMANENT, [
    'library_info',
    'config:core.extension',
  ]);
  return $sources;
}