W3cubDocs

/Drupal 8

protected function HtmlResponseAttachmentsProcessor::processAssetLibraries

protected HtmlResponseAttachmentsProcessor::processAssetLibraries(AttachedAssetsInterface $assets, array $placeholders)

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

File

core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php, line 284

Class

HtmlResponseAttachmentsProcessor
Processes attachments of HTML responses.

Namespace

Drupal\Core\Render

Code

protected function processAssetLibraries(AttachedAssetsInterface $assets, array $placeholders) {
  $variables = [];

  // Print styles - if present.
  if (isset($placeholders['styles'])) {
    // Optimize CSS if necessary, but only during normal site operation.
    $optimize_css = !defined('MAINTENANCE_MODE') && $this->config->get('css.preprocess');
    $variables['styles'] = $this->cssCollectionRenderer->render($this->assetResolver->getCssAssets($assets, $optimize_css));
  }

  // Print scripts - if any are present.
  if (isset($placeholders['scripts']) || isset($placeholders['scripts_bottom'])) {
    // Optimize JS if necessary, but only during normal site operation.
    $optimize_js = !defined('MAINTENANCE_MODE') && !\Drupal::state()->get('system.maintenance_mode') && $this->config->get('js.preprocess');
    list($js_assets_header, $js_assets_footer) = $this->assetResolver->getJsAssets($assets, $optimize_js);
    $variables['scripts'] = $this->jsCollectionRenderer->render($js_assets_header);
    $variables['scripts_bottom'] = $this->jsCollectionRenderer->render($js_assets_footer);
  }

  return $variables;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!HtmlResponseAttachmentsProcessor.php/function/HtmlResponseAttachmentsProcessor::processAssetLibraries/8.1.x