You are here

function nodejs_page_attachments_alter in Node.js integration 8

Implements hook_page_attachments_alter().

File

./nodejs.module, line 322

Code

function nodejs_page_attachments_alter(array &$attachments) {
  if (nodejs_add_js_to_page_check()) {

    // Add Nodejs specific libraries.
    $libraries = [
      'nodejs/socketio',
      'nodejs/init',
    ];

    // Allow modules to add their own libraries.
    foreach (nodejs_get_js_handlers() as $library) {
      $libraries[] = $library;
    }
    foreach ($libraries as $library) {
      if (!in_array($library, $attachments['#attached']['library'])) {
        $attachments['#attached']['library'][] = $library;
      }
    }
  }
}