Problem/Motivation
It is required to send some emails to a specific user before his role expires. For example:
- sending one warning e-mail 1 month before the expiration
- one warning e-mail 10 days before the expiration
- e-mail with the notification that the role has expired.
Proposed resolution
Create a new submodule to implement the new feature. Use the "user.data" service to avoid sending repeated notifications to users.
Remaining tasks
Fix all pipeline errors: cspell, phpcs and phpstanCompatibility with Drupal 11Make the new submodule's configuration form translatableFix configuration language handlingComplete the renaming from points to methodsAdd default config fileAdd info of the new submodule into the main READMEFix error: notification emails are not send in user's preferred language, just in site's default language- More tests
- Review the MR
User interface changes
The new submodule will have a new UI that will allow to configure the notifications.
API changes
None.
Data model changes
None.
Original report by Skin
Hello, I`d like to know if there is a way to send some emails to a specific user before his role expires: for example I`d like to send one warning e-mail 1 month before the expiration, one warning e-mail 10 days before the expiration and a final e-mail with the notification that the role has expired.
Before starting to study Rules module ( I never used it ) i`d like to ask if it is possible to do this with the Rules 8.x module.
May be someone can poin`t me in the right direction?
thanks.
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | interdiff_20-24.txt | 1.02 KB | rcodina |
| #24 | 3036511-24.patch | 25.11 KB | rcodina |
| #20 | 3036511-20.patch | 26.27 KB | heddn |
Issue fork role_expire-3036511
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rcodinaThis would be a new feature: new events should be created and dispatched on the right moment. Check out the current RoleExpiresEvent to find an example (it's dispatched inside role_expire_cron function). I also recommend you to check out Rules module source code.
Comment #3
skinThank you!
Comment #4
rcodinaComment #5
chikeFirst thank you for your work, definitely this feature would be handy and is almost expected to be on this module. Warning messages like one month, 10 days, 5 days and on expiry day (days to be configurable) should be an integral feature of this module IMO. Use cases like in subscriptions, this will be a required functionality.
If I could I would have submitted a patch.
Comment #6
ilya.no commentedHello all,
I need this feature and agree, that it can be placed here, so I've implemented it as separate sub-module. For main module I've only updated event class and cron function to react on expiration event. For notification event I've implemented similar, but separate event. Both events are processed by one subscriber, which sends actual emails. There is also cron function in new module to dispatch new type of events. Notifications are managed on `admin/config/people/role-expire/notification` page. Each notification has email body and subject, checkboxes for possible roles, assigned to this notification and field for number of days before expiration date when notification should be sent. In order to prevent sending same notification several times, I use `user.data` service and keep information there.
Comment #7
voviko commentedTypeError : Argument 1 passed to Egulias\EmailValidator\EmailValidator::isValid() must be of the type string, null givenchange
$message['headers']['Sender'] = \Drupal::config('system.site')->get('mail');Comment #8
voviko commentedComment #9
rcodinaComment #10
rcodinaComment #11
vacho commentedThe last patch have the issue that send the email notification always in default website language. This patch let to send the current language.
Comment #12
vacho commentedThis patch fixes a problem to load the configuration.
Comment #13
vacho commentedSorry, forget the patch 12.
Comment #14
vacho commentedComment #15
heddnActual functionality here works very well. No concerns with that. My nits are mainly about making this a better solution. The main one being around naming, which I recognize is a hard thing. Bumping back to NW.
Calling this a notification point doesn't make as much sense as calling it a notification method. Let's rename this here and elsewhere.
Let's change this to also include Drupal 10.
Comment #16
heddnHere's a fix for #15, along with a test of the new module. It also fixes several D10 incompatible issues. Mainly event dispatcher stuffs. It would be nice to have tests setup again as automated tests aren't executing right now.
Comment #17
rcodina@heddn I enabled testing.
Comment #18
heddn9.5 and 10.1.x both passed green.
Comment #19
heddnRe-rolled for 2.x. It was a trivial re-roll and the diff stats are identical.
Comment #20
heddnAnd here's a 3.x patch.
Comment #21
chike@heddn none of your patches applies on Drupal 9. I am using Drupal 9.5.10.
Comment #22
rcodina@heddn @chike The patch cleanly applies to 3.x but this patch has to be split:
1. Test fixes: See #3378674: Fix failing tests
2. New feature without test fixes
Once ready, this feature will only be committed to 3.x branch.
Comment #23
rcodinaComment #24
rcodinaRemoved changes that overlap with #3378674: Fix failing tests
Comment #25
elvin - albania drupal developerany movement on this? it would be great to have this feature enabled or this module integrated with ECA for more power handling
Comment #26
rcodinaOnce drupal 11 version is released (new 4.x branch), a new MR should be created from current patch.
Comment #27
rcodinaComment #28
rcodinaComment #29
rcodinaComment #31
rcodinaAdded latest patch to a new issue fork and created a MR which targets 4.x branch. Please, don't upload more patches, just use the new issue fork.
Comment #32
rcodinaComment #33
rcodinaComment #34
rcodinaThere are only a few tasks left. Thanks for your contributions!
Comment #35
rcodinaComment #36
rcodinaComment #37
anybody#3362875: Provide ECA integration would also be a good and more flexible alternative maybe?
Comment #38
rcodina@anybody I think both can live together. This feature it's already implemented, we should not force users to install additional modules if not necessary.
Comment #39
elvin - albania drupal developerany movement on this? Would really be helpful to have email notifications
Comment #40
rcodina@elvin - albania drupal developer If you want to use it now you can patch the module via composer patching. It's fully working and it's multilingual. As you can see in the description and recent commits/messages, a lot of work has been done since your previous comment.
Comment #41
elvin - albania drupal developerThank you! Testing it right now and will report on anything i may find!
Comment #42
elvin - albania drupal developerThank you! Testing it right now and will report on anything i may find!
Comment #43
_tarik_ commentedI’ve reviewed the changes in this task to better understand how the feature is intended to work and what adjustments might be beneficial. Based on this, I have several suggestions:
1. The module allows configuring an email notification for one or more roles, but it does not provide an option to set a default notification for all roles. This means administrators must always check whether every role is explicitly selected. To improve this, we could either introduce a setting that controls a default notification for all roles or add fallback behavior to the roles selection list—for example, if no role is selected, the rule would automatically apply to all roles. What do you think?
2. The notification subforms are currently wrapped in a tag. If a site uses many notifications, this could make the page harder to navigate. Replacing the with might make the interface more manageable.
3. The notification subforms currently use auto-generated titles such as “Method #1.” It would be more intuitive to generate titles based on the roles to which the notification applies, or alternatively, provide a field that lets administrators define their own titles. This would make configurations easier to distinguish.
Please let me know what you think about the described changes, and I'll be ready to finish the issue.