Problem/Motivation
I'm working on a site where a specific node type can be posted to groups. These nodes start life unpublished, with a date range field defining the window of time they should be published. I need to automatically notify all group members when one of these nodes is published.
#3076248: Notification toggle on save and edit gives us the possibility to conditionally send group notifications when editing a node.
However, because it all works at the Form API level, if you have something programmatically updating (and in this case, publishing) nodes, there's no way to twiddle those checkboxes and generate the emails.
Proposed resolution
Not entirely sure what's best for this. If there was some code at the hook_ENTITY_TYPE_update() level that looked for the presence of a magic property, I could force this to work with something like:
// Array of Group entity IDs to notify with this node update:
$node->group_notify[] = $group->id();
$node->setNewRevision(TRUE);
$node->setPublished();
$node->save();
Or maybe there should be both an array if you want specific Group IDs (above) or a bool if you want everything:
$node->group_notify_all = TRUE;
Remaining tasks
Decide on how this should work.Implement.Testing.- Automated tests?
- Reviews / refinements.
- Commit.
User interface changes
None. This would be entirely at the Entity API level.
API changes
TBD.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3164688-6.patch | 2.81 KB | dww |
Comments
Comment #2
dwwLooking more closely at the group_notify code, I guess if a node is related to multiple groups, someone might only want to force notifications to certain groups. So maybe
$node->group_notifyshould be an array of group IDs to notify, not a bool. Something like this:or:
Comment #3
dwwAfter quite a bit of manual local testing, I think this is ready.
Not sure where to document this. The README.txt seems both targeted to a less technical audience, and also somewhat incomplete.
Feedback welcome.
Thanks!
-Derek
Comment #4
dwwMore accurate title.
Comment #5
dwwUpon further testing, these particular code paths shouldn't care about the notify mode -- if you programmatically set these properties, we should generate the emails, regardless of 'enforce' vs. 'toggle' mode.
Comment #6
dwwUpon further reflection, 'group_notify_all' vs 'group_notify' seemed a little vague. I think 'group_notify_group_ids' is a better name for the property where you put specific group IDs. I'm thinking someday someone will need a 'group_notify_group_types' to generate notifications to all groups of the given type(s), etc. More self-documenting seems better.
Comment #7
gregcube commentedThis all checks out -- looks great to me. Tested locally, works as expected.
I can affirm to both. README.txt needs to be updated.
Comment #9
dwwLovely, thanks!