function user_js_settings_alter

user_js_settings_alter(&$settings, AttachedAssetsInterface $assets)

Implements hook_js_settings_alter().

File

core/modules/user/user.module, line 111
Enables the user registration and login system.

Code

function user_js_settings_alter(&$settings, AttachedAssetsInterface $assets) {
  // Provide the user ID in drupalSettings to allow JavaScript code to customize
  // the experience for the end user, rather than the server side, which would
  // break the render cache.
  // Similarly, provide a permissions hash, so that permission-dependent data
  // can be reliably cached on the client side.
  $user = \Drupal::currentUser();
  $settings['user']['uid'] = $user->id();
  $settings['user']['permissionsHash'] = \Drupal::service('user_permissions_hash_generator')->generate($user);
}

© 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!user!user.module/function/user_js_settings_alter/8.1.x