function hook_js_settings_alter

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/theme.api.php \hook_js_settings_alter()
  2. 8.9.x core/lib/Drupal/Core/Render/theme.api.php \hook_js_settings_alter()
  3. 11.x core/lib/Drupal/Core/Render/theme.api.php \hook_js_settings_alter()

Perform necessary alterations to the JavaScript settings (drupalSettings).

Parameters

array &$settings: An array of all JavaScript settings (drupalSettings) being presented on the page.

\Drupal\Core\Asset\AttachedAssetsInterface $assets: The assets attached to the current response.

See also

\Drupal\Core\Asset\AssetResolver

Related topics

6 functions implement hook_js_settings_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

common_test_js_settings_alter in core/modules/system/tests/modules/common_test/common_test.module
Implements hook_js_settings_alter().
editor_test_editor_js_settings_alter in core/modules/editor/tests/modules/editor_test/editor_test.module
Implements hook_editor_js_settings_alter().
js_deprecation_test_js_settings_alter in core/modules/system/tests/modules/js_deprecation_test/js_deprecation_test.module
Implements hook_js_settings_alter().
js_testing_log_test_js_settings_alter in core/modules/system/tests/modules/js_testing_log_test/js_testing_log_test.module
Implements hook_js_settings_alter().
system_js_settings_alter in core/modules/system/system.module
Implements hook_js_settings_alter().

... See full list

1 invocation of hook_js_settings_alter()
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php

File

core/lib/Drupal/Core/Render/theme.api.php, line 995

Code

function hook_js_settings_alter(array &$settings, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
    // Add settings.
    $settings['user']['uid'] = \Drupal::currentUser();
    // Manipulate settings.
    if (isset($settings['dialog'])) {
        $settings['dialog']['autoResize'] = FALSE;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.