You are here

function pwa_admin_configuration_sw in Progressive Web App 7.2

Same name and namespace in other branches
  1. 7 pwa.admin.inc \pwa_admin_configuration_sw()

Configure PWA settings for Service Worker.

1 string reference to 'pwa_admin_configuration_sw'
pwa_menu in ./pwa.module
Implements hook_menu().

File

./pwa.admin.inc, line 231
PWA administration forms.

Code

function pwa_admin_configuration_sw() {
  $form = [];
  $form['intro'] = [
    '#markup' => '<p>' . t('Additional settings for the ServiceWorker.') . '</p>',
  ];
  $form['pwa_sw_everywhere'] = [
    '#type' => 'checkbox',
    '#title' => t('Load Serviceworker registration script on all pages'),
    '#description' => t('The call to register the serviceworker will be done on all pages.'),
    '#default_value' => variable_get('pwa_sw_everywhere', FALSE),
  ];
  $form['pwa_sw_phonehome'] = [
    '#type' => 'checkbox',
    '#title' => t('Phone home'),
    '#description' => t('When enabled the serviceworker will check periodically if it is still valid. By default the service worker will stay <a href="@staleurl">active for 24h maximum</a> after the serviceworker file is removed. Enable this feature is you need to invalidate the serviceworker before then.', [
      '@staleurl' => 'https://w3c.github.io/ServiceWorker/#service-worker-registration-stale',
    ]),
    '#default_value' => variable_get('pwa_sw_phonehome', TRUE),
  ];
  $form['pwa_workbox_url'] = [
    '#type' => 'textfield',
    '#title' => t('Path to workbox library'),
    '#description' => t('Provide a path or URL where the main workbox script is located. Leave empty to use the default URL %default.', [
      '%default' => PWA_WORKBOX_URL,
    ]),
    '#default_value' => variable_get('pwa_workbox_url', ''),
  ];
  $form = system_settings_form($form);

  // Wait for all the values to be saved before refreshing cache.
  $form['#submit'][] = 'pwa_admin_clear_cache';
  return $form;
}