You are here

private function HtmlResponseAttachmentsProcessor::getJsAssetCollection in Cookie Content Blocker 8

Collects the JS assets.

Parameters

string $region: The region to retrieve assets for. Can either be 'header' or 'footer'.

Return value

array The JS asset collection for the given region.

2 calls to HtmlResponseAttachmentsProcessor::getJsAssetCollection()
HtmlResponseAttachmentsProcessor::processScripts in src/Render/HtmlResponseAttachmentsProcessor.php
Processes js assets and creates output for the 'scripts' variable.
HtmlResponseAttachmentsProcessor::processScriptsBottom in src/Render/HtmlResponseAttachmentsProcessor.php
Processes js assets and creates output for the 'scripts_bottom' variable.

File

src/Render/HtmlResponseAttachmentsProcessor.php, line 210

Class

HtmlResponseAttachmentsProcessor
Processes attachments of HTML responses.

Namespace

Drupal\cookie_content_blocker\Render

Code

private function getJsAssetCollection(string $region) : array {
  static $header = NULL, $footer = NULL, $processed = FALSE;
  if ($processed) {
    return ${$region} ?? [];
  }
  $optimize_js = !defined('MAINTENANCE_MODE') && !Drupal::state()
    ->get('system.maintenance_mode') && $this->config
    ->get('js.preprocess');
  [
    [
      $allowed_js_assets_header,
      $allowed_js_assets_footer,
    ],
    [
      $allowed_js_assets_header_raw,
      $allowed_js_assets_footer_raw,
    ],
    [
      $blocked_js_assets_header,
      $blocked_js_assets_footer,
    ],
  ] = $this
    ->resolveAssets([
    $this->assetResolver,
    'getJsAssets',
  ], $optimize_js);

  // @codingStandardsIgnoreStart
  $header = $this
    ->getMergedAndSortedAssets($allowed_js_assets_header, $allowed_js_assets_header_raw, $blocked_js_assets_header);
  $footer = $this
    ->getMergedAndSortedAssets($allowed_js_assets_footer, $allowed_js_assets_footer_raw, $blocked_js_assets_footer);

  // We need to extract settings because we want to add extra settings
  // for generated placeholders, so we can identify them. Therefor we
  // render all the scripts first and attach the settings at the end, which
  // at that point will contain our placeholder settings.
  $settings = $header['drupalSettings'] ?? $footer['drupalSettings'] ?? [];
  $settings['position'] = array_key_exists('drupalSettings', $header) ? 'scripts' : 'scripts_bottom';
  $this
    ->mergeSettings($settings);
  unset($header['drupalSettings'], $footer['drupalSettings']);
  $processed = TRUE;
  return ${$region} ?? [];

  // @codingStandardsIgnoreEnd
}