function system_js_settings_build in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/system.module \system_js_settings_build()
- 9 core/modules/system/system.module \system_js_settings_build()
Implements hook_js_settings_build().
Sets values for the core/drupal.ajax library, which just depends on the active theme but no other request-dependent values.
File
- core/
modules/ system/ system.module, line 687 - Configuration system that lets administrators modify the workings of the site.
Code
function system_js_settings_build(&$settings, AttachedAssetsInterface $assets) {
// Generate the values for the core/drupal.ajax library.
// We need to send ajaxPageState settings for core/drupal.ajax if:
// - ajaxPageState is being loaded in this Response, in which case it will
// already exist at $settings['ajaxPageState'] (because the core/drupal.ajax
// library definition specifies a placeholder 'ajaxPageState' setting).
// - core/drupal.ajax already has been loaded and hence this is an AJAX
// Response in which we must send the list of extra asset libraries that are
// being added in this AJAX Response.
/** @var \Drupal\Core\Asset\LibraryDependencyResolver $library_dependency_resolver */
$library_dependency_resolver = \Drupal::service('library.dependency_resolver');
if (isset($settings['ajaxPageState']) || in_array('core/drupal.ajax', $library_dependency_resolver
->getLibrariesWithDependencies($assets
->getAlreadyLoadedLibraries()))) {
// Provide the page with information about the theme that's used, so that
// a later AJAX request can be rendered using the same theme.
// @see \Drupal\Core\Theme\AjaxBasePageNegotiator
$theme_key = \Drupal::theme()
->getActiveTheme()
->getName();
$settings['ajaxPageState']['theme'] = $theme_key;
}
}