You are here

function pwa_preprocess_html in Progressive Web App 7

Same name and namespace in other branches
  1. 7.2 pwa.module \pwa_preprocess_html()

Implements hook_page_alter().

File

./pwa.module, line 271

Code

function pwa_preprocess_html(&$variables) {
  if (!user_access('access pwa')) {
    return;
  }

  // Add manifest.json to HTML
  drupal_add_html_head([
    '#tag' => 'link',
    '#attributes' => [
      'rel' => 'manifest',
      'href' => variable_get('pwa_filecache_manifest', ''),
    ],
  ], 'manifest');

  // Add backup <meta> tag for branding colors. It should always match the
  // variable for the manifest.
  drupal_add_html_head([
    '#tag' => 'meta',
    '#attributes' => [
      'name' => 'theme-color',
      'content' => variable_get('pwa_theme_color', '#ffffff'),
    ],
  ], 'theme_color');

  // Load the Service Worker
  drupal_add_library('pwa', 'serviceworker');
  drupal_add_js([
    'pwa' => [
      'path' => url('pwa/serviceworker/js'),
    ],
  ], 'setting');
}