function system_js_settings_build
system_js_settings_build(&$settings, AttachedAssetsInterface $assets)
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 641
- 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; // Provide the page with information about the individual asset libraries // used, information not otherwise available when aggregation is enabled. $minimal_libraries = $library_dependency_resolver->getMinimalRepresentativeSubset(array_merge( $assets->getLibraries(), $assets->getAlreadyLoadedLibraries() )); sort($minimal_libraries); $settings['ajaxPageState']['libraries'] = implode(',', $minimal_libraries); } }
© 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!modules!system!system.module/function/system_js_settings_build/8.1.x