You are here

pwa_webpush.rules.inc in Progressive Web App 7.2

File

modules/pwa_webpush/pwa_webpush.rules.inc
View source
<?php

function pwa_webpush_rules_action_info() {
  $items = [];
  $notification = [
    'title' => [
      'type' => 'text',
      'label' => t('Notification title'),
      'translatable' => TRUE,
    ],
    'body' => [
      'type' => 'text',
      'label' => t('Notification message'),
      'translatable' => TRUE,
    ],
    'url' => [
      'type' => 'text',
      'label' => t('URL destination'),
      'description' => t('The URL to redirect the user to when clicking on the notification.'),
      'translatable' => TRUE,
    ],
    'icon' => [
      'type' => 'text',
      'label' => t('Notification icon'),
      'description' => t('Chose a icon from the manifest file.'),
      'options list' => 'pwa_webpush_icon_options',
      'restriction' => 'input',
      'optional' => TRUE,
    ],
  ];
  $items['pwa_webpush_send_message_account'] = [
    'label' => t('Send a web push notification to a user account'),
    'group' => t('Push notification'),
    'parameter' => [
      'account' => [
        'type' => 'user',
        'label' => t('User Account'),
        'description' => t('Specify the recipient account for this message.'),
      ],
    ] + $notification,
  ];
  return $items;
}
function pwa_webpush_icon_options() {
  $icons = [];
  foreach (_pwa_manifest_file()['icons'] as $icon) {
    $icons[$icon['src']] = basename($icon['src']) . ' (' . $icon['sizes'] . ')';
  }
  return $icons;
}