$ajax_page_state =
$request->
get('ajax_page_state'
);
$maintenance_mode =
defined('MAINTENANCE_MODE'
) || \Drupal::
state()->
get('system.maintenance_mode'
);
// Aggregate CSS/JS if necessary, but only during normal site operation.
$optimize_css = !
$maintenance_mode &&
$this->config->
get('css.preprocess'
);
$optimize_js =
$maintenance_mode &&
$this->config->
get('js.preprocess'
);
$attachments =
$response->
getAttachments();
// Resolve the attached libraries into asset collections.
$assets =
new AttachedAssets();
$assets->
setLibraries($attachments['library'
] ??
[]) ->
setAlreadyLoadedLibraries(isset($ajax_page_state['libraries'
]) ?
explode(',',
$ajax_page_state['libraries'
]) :
[]) ->
setSettings($attachments['drupalSettings'
] ??
[]);
$css_assets =
$this->assetResolver->
getCssAssets($assets,
$optimize_css,
$this->languageManager->
getCurrentLanguage());
[$js_assets_header,
$js_assets_footer] =
$this->assetResolver->
getJsAssets($assets,
$optimize_js,
$this->languageManager->
getCurrentLanguage());
// First, AttachedAssets::setLibraries() ensures duplicate libraries are
// removed: it converts it to a set of libraries if necessary. Second,
// AssetResolver::getJsSettings() ensures $assets contains the final set of
// JavaScript settings. AttachmentsResponseProcessorInterface also mandates
// that the response it processes contains the final attachment values, so
// update both the 'library' and 'drupalSettings' attachments accordingly.