Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UserHooks.php

function UserHooks::jsSettingsAlter

Implements hook_js_settings_alter().

File

core/modules/user/src/Hook/UserHooks.php, line 111

Class

UserHooks
Hook implementations for user.

Namespace

Drupal\user\Hook

Code

public function jsSettingsAlter(&$settings, AttachedAssetsInterface $assets) : void {
    // 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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal