[4.x] Modernize Page Notifications Implementation

Created on 26 December 2024, 3 months ago

Refactor the Page Notifications module to align with modern Drupal best practices while maintaining backwards compatibility through proper migration paths. The key goals of this refactoring are:

Architecture Changes:

  • Convert subscription storage from content entities (nodes) to custom entities using the Entity API
  • Implement proper dependency injection throughout the codebase to replace direct static Drupal calls
  • Move configuration from custom database tables to Drupal's configuration management system
  • Implement proper service containers and dependency injection for better testability and maintenance
  • Add proper schema validation for configuration entities

Security Improvements:

  • Remove email addresses from URL parameters to prevent logging/exposure
  • Implement proper token validation with expiration handling
  • Improve XSS protection throughout forms and templates
  • Implement proper CSRF protection on all forms
  • Add proper sanitization of user inputs

Code Quality:

  • Implement proper interfaces and type hinting
  • Remove deprecated code patterns and API usage
  • Improve code documentation and add proper PHPDoc blocks
  • Add comprehensive unit and functional tests
  • Remove unused variables and dead code

Feature Improvements:

  • Add token expiration
  • Implement automated cleanup of expired tokens via cron
  • Add better handling of email validation
  • Improve subscription management interfaces
  • Implement proper event dispatching for subscription lifecycle events

Migration Path:

  • Provide upgrade path from 3.x node-based storage
  • Add migration classes for converting existing subscriptions
  • Maintain backwards compatibility where possible
  • Add proper documentation for upgrading

I want to try to do multilingual as well, but honestly not an expert in that area, but I will try to set a good foundation to add that later such as saving a lang pref during subscription etc.

🌱 Plan
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States NicholasS

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

Merge Requests

Comments & Activities

  • Issue created by @NicholasS
  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Got an initial start on the refactor today. Currently it can install, has settings that can be saved, a block to allow subscriptions, a route to see subscriptions, but still needs a lot more work and features. hopefully I get some more time next week.

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS
  • πŸ‡ΊπŸ‡ΈUnited States NicholasS
  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Would a maintainer please take a look at my initial refactor of this module to v4. And update hook should migrate all the old subscriptions. I choose not to try to migrate all the old settings so user will have to redo their templates etc. But would love some feed on what I have so far. I tested it and so far looks to work pretty well for me.

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Recently added Flood protection to the module. The one aspect I think that could use some work is the signup block, would love to make it a button, that spawns a modal(native dialog) and the modal contains the signup form, and posts/updates with error handling in the modal.

    But I think a lot of the other areas of the module are solid, so I am going to open a Merge Request for it so it can get some maintainer attention, would love to merge it to a 4.x branch but Gitlab doesn't allow me to do that, so for now I will MR to the 3.x.

  • πŸ‡ΊπŸ‡ΈUnited States risweb

    Hey nicholass,

    Is there a way to keep customer's settings and templates so after updating this module users don't have to re-create those? Thank you for working on this module and making it better.

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    So I migrated all the config I think I can, some of the "Flow" is a bit different so I am not sure the old templates make 100% sense in the new version. Also there is not "manage subscriptions" page, this version simplifies things and all emails just have an unsubscribe link (like slickdeals/camelcamel etc do it). And some of the old v3 emails are just notifications in the newer version.

    Here are some screenshots

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Drupal Status message after verification link is clicked

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Manual Addition: Most my clients have emails often from other sources like paper signup forms etc

    Migration page with auto complete to transfer subscriptions from one entity to another

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Manual Notification: Some people may not want to edit/modify the content which would affect the date, maybe its a reminder that something is the last day or something, so put in a manual notification option.

  • πŸ‡ΊπŸ‡ΈUnited States risweb

    Hey nicholass,

    I tested v4 and over all everything looks good. Thank you for all the efforts you putting into this module! I found two things:

    1. I don't get the verification link (see attached screenshot) only text "Please confirm your subscription" not hyperlinked. Where do I configure that or did I miss something? I also attached the screenshot for templates settings.

    2. After I submit my form to subscribe to a page, I get this message: The subscription form is temporarily unavailable.
    Is this message is because I just subscribed to the page and module is waiting to verification link? Can we modify that message to custom test there? The "The subscription form is temporarily unavailable." looks to me like "something is not working right".

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Added more features to it such as verified HTML emails are created, allowing hooks and headers and footers so people can customize the email templates as well. Along with an option for the block to be a button and a modal to save on UI real-estate. Also added logic for people who are already subscribed and attempting to re-subscribe.

    Tested with a core Drupal 10 install as well, and improved the

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    @risweb

    #1 I think was a bug and I fixed it in commit

    #2 Yeah I noticed that as well I will have to look into that maybe today or early next week, I can have that message customized for sure, I don't know why it just doesn't show the form again so yeah I will look more into that.

    I also plan to test Drupal 11 as well to make sure it works there. So I will have a few more commits I think to add but thanks for the initial review.

    Do you see any other features missing that the original module had?

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    @risweb #2 should be fixed now.

    Anything else off you notice let me know.

  • πŸ‡ΊπŸ‡ΈUnited States risweb

    Just tried to test new code and got this error when trying to subscribe to a page:
    TypeError: Cannot access offset of type string on string in Drupal\page_notifications\Mail\PageNotificationsMailHandler->buildVerificationEmail() (line 138 of modules/contrib/page_notifications/src/Mail/PageNotificationsMailHandler.php).

    I uninstalled and then tried to install latest version and it looks like mimemail module is now required to install page notifications module ( page notifications - requires mimemail module.png). Our website is using different module for mail system. But I went ahead and installed mimemail module to test page notifications module. I didn't make any changes to templates in configuration of the module, just left it the way you have it by default.

    1. Modal window needs X (close) or cancel button.
    2. Currently page notifications module have confirmation messages and error messages displayed in modal window as well. Your version is using drupal core message. Can we keep the old style with having modal window like in this screenshot page notifications - modal window messages.png
    3. Not formatted verification email (see attached screenshot page notifications - verification email.png)
    4. Page not found after clicking on verification link on the email: page notifications - page not found when clicking on verification link.png

    I really like the changes you are making and implementing new features and security checks to page notifications module.

  • πŸ‡ΊπŸ‡ΈUnited States risweb

    Modal window DOES have close button. Sorry, it was black on black and I didn't notice it.

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    @risweb Replying to Comment #17

    So after testing with Drupal CMS 1.0 I switched the mail module to "symphony mailer lite" since that seems to be what they went with and is Drupal 11 compatible, Mimemail is not so my sites I guess will have to switch as well.

    Replies to:

    1. Ok so if the subscriber block is set to a modal, Yeah I can try to get it to have the success message kept in the modal, your right, right now once you complete the modal signup form it just dismisses and the page has the message in it. Not a problem I don't think.

    2. I think this was a double HTML escape issue, I also switched to sympohny mailer lite since thats what Drupal CMS choose and I figured the core guys did their research on the best mailer, so see if the most recent version has proper HTML emails.

    3. Based on your screenshot page%20notifications%20-%20verification%20email.png is perhaps your "text format" truncating the url, I see the purple text says /verify.... so I think that could be a text format setting issue. Is that the Maximum link text length? Could you test that out an see, none of my testing had truncated links like that. Maybe also this is fixed after I fixed the double escape HTML issue that I mentioned in #2

    Thanks for the feedback, I think its getting close!

Production build 0.71.5 2024