You are here

protected function AmpHtmlResponseAttachmentsProcessor::processAssetLibraries in Accelerated Mobile Pages (AMP) 8.2

Same name and namespace in other branches
  1. 8.3 src/Render/AmpHtmlResponseAttachmentsProcessor.php \Drupal\amp\Render\AmpHtmlResponseAttachmentsProcessor::processAssetLibraries()
  2. 8 src/Render/AmpHtmlResponseAttachmentsProcessor.php \Drupal\amp\Render\AmpHtmlResponseAttachmentsProcessor::processAssetLibraries()

Processes asset libraries into render arrays.

Parameters

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

array $placeholders: The placeholders that exist in the response.

Return value

array An array keyed by asset type, with keys:

  • styles
  • scripts
  • scripts_bottom

Overrides HtmlResponseAttachmentsProcessor::processAssetLibraries

File

src/Render/AmpHtmlResponseAttachmentsProcessor.php, line 80

Class

AmpHtmlResponseAttachmentsProcessor
Processes attachments of AMP HTML responses.

Namespace

Drupal\amp\Render

Code

protected function processAssetLibraries(AttachedAssetsInterface $assets, array $placeholders) {
  $variables = [];
  if ($this->ampContext
    ->isAmpRoute()) {
    foreach ($assets->libraries as $delta => $library) {
      if (strpos($library, 'amp/') === FALSE) {
        unset($assets->libraries[$delta]);
      }
    }

    // Print amp scripts - if any are present.
    if (isset($placeholders['scripts']) || isset($placeholders['scripts_bottom'])) {

      // Do not optimize JS.
      $optimize_js = FALSE;
      list($js_assets_header, $js_assets_footer) = $this->assetResolver
        ->getJsAssets($assets, $optimize_js);
      $variables['scripts'] = $this->jsCollectionRenderer
        ->render($js_assets_header);
    }
  }
  else {
    $variables = parent::processAssetLibraries($assets, $placeholders);
  }
  return $variables;
}