You are here

function nodejs_js_settings_alter in Node.js integration 8

Implements hook_js_settings_alter().

File

./nodejs.module, line 301

Code

function nodejs_js_settings_alter(array &$settings, AttachedAssetsInterface $assets) {
  if (nodejs_add_js_to_page_check()) {
    $nodejs_config = nodejs_get_config();
    $settings['nodejs'] = [
      'nodejs' => $nodejs_config['nodejs'],
      'client' => $nodejs_config['client'],
      'authToken' => nodejs_auth_get_token(\Drupal::service('session')),
    ];

    // Add generated content tokens.
    $tokens = nodejs_get_nodejs()
      ->getContentTokens();
    foreach ($tokens as $channel => $token) {
      $settings['nodejs']['contentTokens'][$channel] = $token;
    }
  }
}