You are here

function nodejs_add_js_to_page_check in Node.js integration 8

Same name and namespace in other branches
  1. 7 nodejs.module \nodejs_add_js_to_page_check()

Check if we should add the node.js js to the page.

We check the url, and whether or not the admin has closed down access to auth users only.

2 calls to nodejs_add_js_to_page_check()
nodejs_js_settings_alter in ./nodejs.module
Implements hook_js_settings_alter().
nodejs_page_attachments_alter in ./nodejs.module
Implements hook_page_attachments_alter().

File

./nodejs.module, line 262

Code

function nodejs_add_js_to_page_check() {
  $account = \Drupal::currentUser();
  $path = \Drupal::service('path_alias.manager')
    ->getAliasByPath(Url::fromRoute('<current>')
    ->toString());
  $config_paths = \Drupal::config('nodejs.config')
    ->get('pages');
  $valid_page = \Drupal::service('path.matcher')
    ->matchPath($path, $config_paths);
  if (\Drupal::config('nodejs.config')
    ->get('authenticated_users_only')) {
    $valid_user = $account
      ->id() > 0;
  }
  else {
    $valid_user = TRUE;
  }
  return $valid_page && $valid_user;
}