Commit 134a2e55 authored by George's avatar George
Browse files

Issue #3318255 - Add in onesignal.api.php file and minor adjustments.

parent 2580b078
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ To access this functionality, go to:
Configuration > Web services > OneSignal > Notifications (tab)

Active or ongoing notifications can be stopped if able to do so. Button will
appear on notifications table if the action permits.
appear on notifications' table if the action permits.

Devices registered with the site are also listed out in table format.

onesignal.api.php

0 → 100644
+18 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Hooks specific to the OneSignal module.
 */

/**
 * Add extra js to be fired on OneSignal.push().
 *
 * Invoked on onesignal_page_attachments().
 *
 * @return string
 *   Returns the extra js to be added.
 */
function hook_onesignal_extra_js(): string {
  return '';
}
+45 −43
Original line number Diff line number Diff line
@@ -8,7 +8,46 @@
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Drupal\Core\Render\Markup;

/**
 * Implements hook_help().
 */
function onesignal_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the onesignal module.
    case 'help.page.onesignal':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This module provides integration with the free HTTP Web Push service from OneSignal  allowing visitors to subscribe for notifications and site owners to send notifications to the subscribers.') . '</p>';
      $output .= '<h3>' . t('Prerequisites') . '</h3>';
      $output .= '<p>' . t('You must create an account at @url to configure your Web app, obtain an App ID and download some files.', [
        '@url' => Link::fromTextAndUrl('OneSignal.com', Url::fromUri('https://onesignal.com', []))
          ->toString(),
      ]) . '</p>';
      $output .= '<p>' . t('Once you have created your account at OneSignal.com:') . '</p>';
      $output .= '<ol>';
      $output .= '<li>' . t('Add a new app') . '</li>';
      $output .= '<li>' . t('On the &quot;Select one platform&quot; screen, chose &quot;Web Push&quot;') . '</li>';
      $output .= '<li>' . t('On the &quot;Chose Integration&quot; screen, chose &quot;Custom Code&quot;') . '</li>';
      $output .= '<li>' . t('Enter your site name, URL and Icon URL.') . '</li>';
      $output .= '<li>' . t('Click &quot;Save&quot;') . '</li>';
      $output .= '</ol>';
      $output .= '<p>' . t('At this point you will be given a link to download the <strong>OneSignal SDK</strong> files. Download the Zip file, extract the content, and upload the following three files to the root of your website:') . '</p>';
      $output .= '<ul>';
      $output .= '<li>' . t('OneSignalSDKUpdaterWorker.js') . '</li>';
      $output .= '<li>' . t('OneSignalSDKWorker.js') . '</li>';
      $output .= '</ul>';
      $output .= '<p>' . t("OneSignal will give you also a code to add to the <strong><em>&lt;head&gt;</em></strong> of your site; however YOU DON'T NEED THE FULL CODE, all you need from this code is your <em><strong>appId</strong></em>.") . '</p>';
      $output .= '<h3>' . t('Configuration') . '</h3>';
      $output .= '<p>' . t('This module defines the permission <em>Administer OneSignal settings</em>. Users should be granted this permission before they can make changes to the configurations of this module.') . '</p>';
      $output .= '<p>' . t('To configure this module, go to: <em><strong>Configuration &gt; Web services &gt; OneSignal</strong></em>') . '</p>';
      $output .= '<p>' . t('Provide the required parameters as instructed on that page.') . '</p>';
      $output .= '<h3>' . t('Bugs/Features/Patches') . '</h3>';
      $output .= '<p>' . t('If you want to report bugs, feature requests, or submit a patch, please do so at the project page on the Drupal web site.') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_page_attachments().
@@ -91,7 +130,11 @@ function onesignal_page_attachments(&$attachments) {
      $config['promptOptions']['cancelButtonText'] = $config_manager->getCancelButtonText();
    }
  }

  // Grab any extra js to be included.
  $extra_js = \Drupal::service('module_handler')->invokeAll('onesignal_extra_js');

  // Build up inline js.
  $inline_js = [
    '#type' => 'inline_template',
    '#template' => "
@@ -108,8 +151,8 @@ function onesignal_page_attachments(&$attachments) {
  ];
  $inline_js = \Drupal::service('renderer')->renderPlain($inline_js);

  // Attach inline js.
  $attachments['#attached']['html_head'][] = [
    // The data.
    [
      // Add a <script> tag.
      '#tag' => 'script',
@@ -123,44 +166,3 @@ function onesignal_page_attachments(&$attachments) {
    'onesignal-js',
  ];
}

/**
 * Implements hook_help().
 */
function onesignal_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the onesignal module.
    case 'help.page.onesignal':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This module provides integration with the free HTTP Web Push service from OneSignal  allowing visitors to subscribe for notifications and site owners to send notifications to the subscribers.') . '</p>';
      $output .= '<h3>' . t('Prerequisites') . '</h3>';
      $output .= '<p>' . t('You must create an account at @url to configure your Web app, obtain an App ID and download some files.', [
        '@url' => Link::fromTextAndUrl('OneSignal.com', Url::fromUri('https://onesignal.com', []))
          ->toString(),
      ]) . '</p>';
      $output .= '<p>' . t('Once you have created your account at OneSignal.com:') . '</p>';
      $output .= '<ol>';
      $output .= '<li>' . t('Add a new app') . '</li>';
      $output .= '<li>' . t('On the &quot;Select one platform&quot; screen, chose &quot;Web Push&quot;') . '</li>';
      $output .= '<li>' . t('On the &quot;Chose Integration&quot; screen, chose &quot;Custom Code&quot;') . '</li>';
      $output .= '<li>' . t('Enter your site name, URL and Icon URL.') . '</li>';
      $output .= '<li>' . t('Click &quot;Save&quot;') . '</li>';
      $output .= '</ol>';
      $output .= '<p>' . t('At this point you will be given a link to download the <strong>OneSignal SDK</strong> files. Download the Zip file, extract the content, and upload the following three files to the root of your website:') . '</p>';
      $output .= '<ul>';
      $output .= '<li>' . t('OneSignalSDKUpdaterWorker.js') . '</li>';
      $output .= '<li>' . t('OneSignalSDKWorker.js') . '</li>';
      $output .= '</ul>';
      $output .= '<p>' . t("OneSignal will give you also a code to add to the <strong><em>&lt;head&gt;</em></strong> of your site; however YOU DON'T NEED THE FULL CODE, all you need from this code is your <em><strong>appId</strong></em>.") . '</p>';
      $output .= '<h3>' . t('Configuration') . '</h3>';
      $output .= '<p>' . t('This module defines the permission <em>Administer OneSignal settings</em>. Users should be granted this permission before they can make changes to the configurations of this module.') . '</p>';
      $output .= '<p>' . t('To configure this module, go to: <em><strong>Configuration &gt; Web services &gt; OneSignal</strong></em>') . '</p>';
      $output .= '<p>' . t('Provide the required parameters as instructed on that page.') . '</p>';
      $output .= '<h3>' . t('Bugs/Features/Patches') . '</h3>';
      $output .= '<p>' . t('If you want to report bugs, feature requests, or submit a patch, please do so at the project page on the Drupal web site.') . '</p>';
      return $output;

    default:
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class OneSignalNotificationForm extends FormBase {
      '#type' => 'textfield',
      '#title' => $this->t('Headings'),
      '#description' => $this->t("Web Push requires a heading but can be omitted from request since defaults to the Site Name set in OneSignal Settings."),
      '#default_value' => isset($notification['headings'][$language->getId()]) ? $notification['headings'][$language->getId()] : '',
      '#default_value' => $notification['headings'][$language->getId()] ?? '',
      '#required' => TRUE,
    ];
    if ($notification) {
@@ -136,7 +136,7 @@ class OneSignalNotificationForm extends FormBase {
      '#type' => 'textarea',
      '#title' => $this->t('Contents'),
      '#description' => $this->t("The notification's content (excluding the title), a map of language codes to text for each language."),
      '#default_value' => isset($notification['contents'][$language->getId()]) ? $notification['contents'][$language->getId()] : '',
      '#default_value' => $notification['contents'][$language->getId()] ?? '',
      '#rows' => 5,
      '#resizable' => 'vertical',
      '#required' => TRUE,