You are here

function pwa_webpush_admin_configuration in Progressive Web App 7.2

Configure PWA settings for Web Push notifications.

1 string reference to 'pwa_webpush_admin_configuration'
pwa_webpush_menu in modules/pwa_webpush/pwa_webpush.module
Implements hook_menu().

File

modules/pwa_webpush/pwa_webpush.admin.inc, line 12
PWA administration forms.

Code

function pwa_webpush_admin_configuration() {
  $form = [];
  $form['pwa_webpush_autoregister'] = [
    '#type' => 'checkbox',
    '#title' => t('Autoregister Push notifications'),
    '#description' => t('For users who granted the notification permission, we can autoregister them to push notifications. This helps to keep users subscribed when the serviceworker changes.'),
    '#default_value' => (bool) variable_get('pwa_webpush_autoregister', TRUE),
  ];
  $form['webpush'] = [
    '#type' => 'fieldset',
    '#title' => t('WebPush library settings'),
    '#description' => t('Settings for the <code>minishlink/web-push</code> library'),
  ];
  $payload_length = (string) Encryption::MAX_PAYLOAD_LENGTH;
  $form['webpush']['pwa_webpush_notification_padding'] = [
    '#type' => 'textfield',
    '#title' => t('Automatic padding size'),
    '#required' => TRUE,
    '#attributes' => [
      'min' => 0,
      'max' => $payload_length,
    ],
    '#default_value' => variable_get('pwa_webpush_notification_padding', PWA_WEBPUSH_AUTOMATIC_PADDING_LIMIT),
    '#size' => 5,
    '#description' => t('Automatic padding is a security feature. If set higher than @limit it is possible to have <a href="@webpush_firefox">issues delivering notifications</a> to Firefox mobile. The webpush library default is @default.', [
      '@limit' => PWA_WEBPUSH_AUTOMATIC_PADDING_LIMIT,
      '@webpush_firefox' => 'https://github.com/web-push-libs/web-push-php/issues/108#issuecomment-390811099',
      '@default' => Encryption::MAX_COMPATIBILITY_PAYLOAD_LENGTH,
    ]),
  ];
  $form['webpush']['pwa_webpush_notification_batchsize'] = [
    '#title' => t('Delivery batch size'),
    '#type' => 'textfield',
    '#default_value' => variable_get('pwa_webpush_notification_batchsize', 1000),
    '#size' => 5,
    '#description' => t("If you send tens of thousands notifications at a time, you may get memory overflows due to how endpoints are called in Guzzle. In order to fix this, WebPush sends notifications in batches. The default size is 1000. Depending on your server configuration (memory), you may want to decrease this number."),
  ];
  $form['webpush']['pwa_webpush_notification_ttl'] = [
    '#title' => t('Notification Time To Live (in seconds)'),
    '#type' => 'select',
    '#options' => [
      '2419200' => t('4 weeks'),
      '86400' => t('24 hours'),
      '43200' => t('12 hours'),
      '0' => t('None (0s)'),
    ],
    '#default_value' => variable_get('pwa_webpush_notification_ttl', 2419200),
    '#description' => t("Defines how long a push message is retained by the push service (eg. Mozilla) in case the user browser is not yet accessible (eg. is not connected). You may want to use a very long time for important notifications. The default TTL is 4 weeks. However, if you send multiple nonessential notifications, set a TTL of 0: the push notification will be delivered only if the user is currently connected. For other cases, you should use a minimum of one day if your users have multiple time zones, and if they don't several hours will suffice."),
  ];
  $form['webpush']['vapid'] = [
    '#type' => 'fieldset',
    '#title' => t('Voluntary Application Server Identification'),
    '#description' => t('Manage <a href="@vapid">VAPID</a> configuration for Web Push.', [
      '@vapid' => 'https://tools.ietf.org/html/draft-ietf-webpush-vapid-01',
    ]),
    '#collapsible' => TRUE,
    '#collapsed' => !empty(variable_get('pwa_webpush_vapid_public', '')) && !empty(variable_get('pwa_webpush_vapid_private', '')),
  ];
  $form['webpush']['vapid']['pwa_webpush_vapid_subject'] = [
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#required' => TRUE,
    '#description' => t('Optional, Contact details, can be a mailto: or https: URI.'),
    '#default_value' => variable_get('pwa_webpush_vapid_subject', 'mailto:' . variable_get('site_mail', '')),
  ];
  $form['webpush']['vapid']['pwa_webpush_vapid_public'] = [
    '#type' => 'textfield',
    '#title' => t('Public key'),
    // 87 char string
    '#size' => 120,
    '#required' => TRUE,
    '#description' => t('Base64 encoded private key.'),
    // If the key is already set it can not be changed in the UI.
    '#disabled' => !empty(variable_get('pwa_webpush_vapid_public', '')),
    '#default_value' => variable_get('pwa_webpush_vapid_public', ''),
  ];
  $form['webpush']['vapid']['pwa_webpush_vapid_private'] = [
    '#type' => 'textfield',
    '#title' => t('Private key'),
    // 43 char string
    '#size' => 60,
    '#required' => TRUE,
    '#description' => t('Base64 encoded private key.'),
    // If the key is already set it can not be changed in the UI.
    '#disabled' => !empty(variable_get('pwa_webpush_vapid_private', '')),
    '#default_value' => variable_get('pwa_webpush_vapid_private', ''),
  ];
  $form = system_settings_form($form);
  return $form;
}