Message won't dismiss

Created on 13 October 2022, about 2 years ago
Updated 20 November 2023, about 1 year ago

Problem/Motivation

In evaluating this module (thanks for saving us weeks of time), I've discovered several things but mostly around not being able to dismiss the message with the Close button.

Steps to reproduce

Using a fresh install of Drupal 9.4.8, the Olivero theme, and 3 contrib modules: admin_toolbar, module_filter, and notification_message. I also have a single Article node.

My basic setup for testing, which basically sets up the block to display on all pages.

  • Created a new message type: "Offline"
    • Allows conditions, entity:node selected
    • Dismiss enabled, default "Close" text
    • Custom field "new Field": text/(plain)
    • Manage display has been modified to show only the Message and New Field fields are enabled
    • Had created a "Full" view mode but unchecked
  • New message using Offline, "Weekly".
    • Theme: none
    • Path: <front> and /admin/*
    • Custom field has text
  • Block placed in Hero region (Olivero)
    • Display title: no
    • Display mode: default (note that "Full" is available even though disabled on form display)
    • Message type: Neither Global nor Offline selected.
    • No other visibility restrictions

In doing various testing of said setup, I'm seeing the following behaviors:

  • On all internal pages, I see the block description (not block title) and the 2 expected fields from the default view mode
    • Clicking Close, the 2 fields are dismissed but the description is still visible
  • On home and node pages, you just see the 2 fields
    • Clicking Close on content pages, nothing happens

Inspecting the elements, apparently the js library is not being loaded on content pages, but is for the admin ones.

Also, if you enable the block title on the block config, when I got the dismissing to work (see below), the block title was still visible while the block content went away. This was only true for the non-admin changes. The block title never shows on the admin pages.

Proposed resolution

After extensive debugging with PHPStorm and xdebug, I've made 3 changes:

  • NotificationMessageBlock.php: commented out lines 185, 187 - bypass if statement so js lib is always added to the build array
    • This ensures that the js lib is always loaded for each page
  • notification-message.html.twig: line 49 - changed "/" to "#"
    • On the node page, when clicking on Close, it would go back to home page
  • notification_message.libraries.yml: added - core/jquery at end of file under dependencies
    • For anonymous users, there was a console error preventing the dismissal to work (see attached)

Remaining tasks

I'd be happy to supply patches but wanted to get this written up first and get feedback. There's apparently some logic issue to load the js lib but couldn't quite figure that out. Does it really hurt to just load it always with the module? It's very small. And before making the 1st change above, I could see that it was being loaded on the admin pages, just not home or node pages.

One last thing, on the initial configuring of the module, when you create a first new message, it defaults to to current date/time for the start and end is +2 days. The block never appears, even if you change the start to an hour earlier. Now if you change it to a day earlier, then you finally see it. Note that it always says published in all cases.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024