Add support for modal window

Created on 19 July 2024, 4 months ago
Updated 23 July 2024, 4 months ago

According to https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe#r..., best practice for accepting broswer notifications is to use a user gesture or CTA on the site to "opt in" to notifications. This is compounded by the latest versions of Safari and Firefox insisting on a User gesture before accepting a new Notification

This is not only best practice — you should not be spamming users with notifications they didn't agree to — but going forward browsers will explicitly disallow notifications not triggered in response to a user gesture. Firefox is already doing this from version 72, for example.

This feature has been more less implemented on advanced_pwa module

Push Notification Icon: This is the icon that is used on the push notifications.
Prompt Settings:
Title
Prompt message
Confirm button
Decline button
Display type: Drupal Modal, Embedded and Bootstrap 5 Modal.
Repeat prompt: How many days to wait until showing the prompt.

https://www.drupal.org/project/advanced_pwa

I think it would be great to have a modal window here. This would enable a modal popup to be shown on browsers that require user. This could also be the shown by default for "all" browsers as recommended by mozilla.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom 2dareis2do

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @2dareis2do
  • 🇬🇧United Kingdom 2dareis2do

    markup for bs 5.3 modal window is as follows:

    <div class="modal" tabindex="-1">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">Modal title</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <p>Modal body text goes here.</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

    see https://getbootstrap.com/docs/5.3/components/modal/

  • 🇬🇧United Kingdom 2dareis2do

    Added patch that adds a modal window. This requires the following:

    1. new modal block type to be created
    2. The following template or similar to be added for this new block type
    3. Bootstrap based theme

    {#
    /**
     * @file
     * Default theme implementation to display a block.
     *
     * Available variables:
     * - plugin_id: The ID of the block implementation.
     * - label: The configured label of the block if visible.
     * - configuration: A list of the block's configuration values.
     *   - label: The configured label for the block.
     *   - label_display: The display settings for the label.
     *   - provider: The module or other provider that provided this block plugin.
     *   - Block plugin specific settings will also be stored here.
     * - content: The content of this block.
     * - attributes: array of HTML attributes populated by modules, intended to
     *   be added to the main container tag of this template.
     *   - id: A valid HTML ID and guaranteed unique.
     * - title_attributes: Same as attributes, except applied to the main title
     *   tag that appears in the template.
     * - content_attributes: Same as attributes, except applied to the main content
     *   tag that appears in the template.
     * - title_prefix: Additional output populated by modules, intended to be
     *   displayed in front of the main title tag that appears in the template.
     * - title_suffix: Additional output populated by modules, intended to be
     *   displayed after the main title tag that appears in the template.
     *
     * @see template_preprocess_block()
     *
     * @ingroup themeable
     */
    #}
    {%
      set classes = [
        'block',
        'block-' ~ configuration.provider|clean_class,
        'block-' ~ plugin_id|clean_class,
        'mb-3',
        'modal',
        'fade',
      ]
    %}
    {% set content_exists = content|render|striptags('<img><video><audio><drupal-render-placeholder>')|trim is not empty %}
    {% set label_exists = label|render|striptags('<img><video><audio><drupal-render-placeholder>')|trim is not empty %}
    {% set title_prefix_exists = title_prefix|render|striptags('<img><video><audio><drupal-render-placeholder>')|trim is not empty %}
    
    {% if content_exists or label_exists or title_prefix_exists %}
    <div{{ attributes.addClass(classes) }} tabindex="-1" aria-hidden="true">
      <div class="modal-dialog">
      {{ title_prefix }}
      {% if label %}
      <div class="modal-header">
        <h2{{ title_attributes.addclass('modal-title', 'fs-5') }}>{{ label }}</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      {% endif %}
      {{ title_suffix }}
      {% block content %}
      <div{{ content_attributes.addClass('content', 'modal-body') }}>
        {{ content }}
      </div>
      {% endblock %}
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Configure</button>
      </div>
    </div>
    {% endif %}
    
  • 🇬🇧United Kingdom 2dareis2do

    Attached screenshots show the user journey. When Web Push Notifications are enabled from Drupal end, users is prompted to set their browser preference (accept or reject) for notifications on first visit, only if web push notification response is rejected due to requirement for a user gesture.

    Once accepted or rejected the notification preference is stored in the browser (until cleared) and the user should not be prompted again (unless they delete their notification setting for this site).

    What is somewhat peculiar for Mac users is that there are also site settings that can be also be viewed globally. Howver for Firefox and Chrome users, there is a single setting. This is peculiar as the sites are still managed from the web browser. This is how Safari manages notifications as well.

    Also I really do not know what the benefit of ensuring that notifications are set per user gesture. This just means that an additional step is required afaict. Not great.

Production build 0.71.5 2024