// loaded, get the JavaScript settings assets, and convert them into a
// single "regular" JavaScript asset.
$libraries_to_load =
$this->
getLibrariesToLoad($assets);
$settings_required =
in_array('core/drupalSettings',
$libraries_to_load) ||
in_array('core/drupalSettings',
$this->libraryDependencyResolver->
getLibrariesWithDependencies($assets->
getAlreadyLoadedLibraries()));
$settings_have_changed =
count($libraries_to_load) > 0 ||
count($assets->
getSettings()) > 0;
// Initialize settings to FALSE since they are not needed by default. This
// distinguishes between an empty array which must still allow
// hook_js_settings_alter() to be run.
$settings = FALSE;
if ($settings_required &&
$settings_have_changed) { $settings =
$this->
getJsSettingsAssets($assets);
// Allow modules to add cached JavaScript settings.
$this->moduleHandler->
invokeAllWith('js_settings_build',
function Dcallable
$hook, string
$module) use (&
$settings,
$assets) { $hook($settings,
$assets);
});
} $settings_in_header =
in_array('core/drupalSettings',
$header_js_libraries);
$this->cache->
set($cid,
[$js_assets_header,
$js_assets_footer,
$settings,
$settings_in_header], CacheBackendInterface::CACHE_PERMANENT,
['library_info'
]);
} if ($settings !== FALSE
) { // Attached settings override both library definitions and