function addtohomescreen_page_attachments in Add to homescreen 8
Implements hook_page_attachments().
File
- ./
addtohomescreen.module, line 11 - Integrates the 'Add to homescreen' library with Drupal.
Code
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;
}
}