You are here

addtohomescreen.module in Add to homescreen 8

Same filename and directory in other branches
  1. 7 addtohomescreen.module

Integrates the 'Add to homescreen' library with Drupal.

File

addtohomescreen.module
View source
<?php

/**
 * @file
 * Integrates the 'Add to homescreen' library with Drupal.
 */

/**
 * Implements hook_page_attachments().
 */
function addtohomescreen_page_attachments(array &$page) {
  $library = \Drupal::service('library.discovery')
    ->getLibraryByName('addtohomescreen', 'addtohomescreen');
  if ($library && isset($library['js'][0]['data']) && file_exists($library['js'][0]['data'])) {
    $config = \Drupal::config('addtohomescreen.settings');
    $settings = [
      'debug' => $config
        ->get('debug'),
      'modal' => $config
        ->get('modal'),
      'mandatory' => $config
        ->get('mandatory'),
      'skipFirstVisit' => $config
        ->get('skipfirstvisit'),
      'autostart' => $config
        ->get('autostart'),
      'icon' => $config
        ->get('icon'),
      'startDelay' => $config
        ->get('startdelay'),
      'lifespan' => $config
        ->get('lifespan'),
      'displayPace' => $config
        ->get('displaypace'),
      'maxDisplayCount' => $config
        ->get('maxdisplaycount'),
    ];
    if ($config
      ->get('use_custom_message')) {
      $settings['message'] = $config
        ->get('message');
    }
    $page['#attached']['library'][] = 'addtohomescreen/addtohomescreen';
    $page['#attached']['library'][] = 'addtohomescreen/set_up';
    $page['#attached']['drupalSettings']['addtohomescreen'] = $settings;
  }
}

Functions