function NavigationHooks::jsSettingsAlter

Implements hook_js_settings_alter().

File

core/modules/navigation/src/Hook/NavigationHooks.php, line 276

Class

NavigationHooks
Hook implementations for navigation.

Namespace

Drupal\navigation\Hook

Code

public function jsSettingsAlter(array &$settings, AttachedAssetsInterface $assets) : void {
    // If Navigation's user-block library is not installed, return.
    if (!in_array('navigation/internal.user-block', $assets->getLibraries())) {
        return;
    }
    // Provide the user name 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.
    $settings['navigation']['user'] = $this->currentUser
        ->getAccountName();
}

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