You are here

function coffee_page_attachments in Coffee 8

Implements hook_page_attachments().

File

./coffee.module, line 38
Coffee primary module file.

Code

function coffee_page_attachments(array &$attachments) {
  if (\Drupal::currentUser()
    ->hasPermission('access coffee')) {
    $config = \Drupal::config('coffee.configuration');
    $cache_tags = isset($attachments['#cache']['tags']) ? $attachments['#cache']['tags'] : [];
    $attachments['#cache']['tags'] = Cache::mergeTags($cache_tags, $config
      ->getCacheTags());
    $data_path = Url::fromRoute('coffee.get_data')
      ->getInternalPath();
    $attachments['#attached']['library'][] = 'coffee/drupal.coffee';
    $attachments['#attached']['drupalSettings']['coffee'] = [
      'dataPath' => $data_path,
      'maxResults' => $config
        ->get('max_results'),
    ];
  }
}