Summary
Allows for entity reference fields that reference user profiles to be used as the source for a Workbench Email template recipient.
Use Case
A common use case that I've run into on a few projects involves assigning content to an individual and emailing that user to notify them that their review has been requested.
I've accomplished this in the past by adding two fields to nodes where I'd like this functionality:
- an entity reference field that references user profiles
- an email address field
Then, using hook_ENTITY_TYPE_presave() I would look up the email address for that particular user and copy over the user's email address to the email field. This would allow me to use the built in functionality in Workbench Email that references a value from an email address field. Rather than continuing with this approach, I added functionality to Workbench Email to allow for entity reference fields to be used.
Approach
The attached patch augments Workbench Email by using the same techniques for discovering entity reference fields as Workbench Email currently uses for email address fields.
How to Use
- Add in the following patch to your codebase (preferably through composer)
- Add an entity reference field that targets user entities to a node
- You may now use this field when setting up your email templates
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | 2923232-user-reference-24.patch | 18.66 KB | larowlan |
| #22 | 2923232-user-reference-22.patch | 18.66 KB | larowlan |
| #20 | 2923232-user-reference-20.patch | 16.76 KB | larowlan |
| #18 | 2923232-user-reference-18.patch | 15.99 KB | larowlan |
| #16 | 2923232-user-reference-16.patch | 12.12 KB | larowlan |
Comments
Comment #2
patrickfwestonComment #3
larowlanI would prefer to focus on #2897697: Refactor recipient types into plugins which would allow this to be done in a decoupled fashion
Comment #4
patrickfwestonI'll look into that and will try to contribute if possible.
Comment #5
larowlanwaiting on #2897697: Refactor recipient types into plugins
Comment #6
larowlanBuilding on top of #2897697: Refactor recipient types into plugins
Comment #7
larowlanpatch against plugins refactor (do not test file) and full patch including that for testing
Comment #9
larowlanMissed a spot
Comment #11
larowlanforgot --binary
Comment #12
larowlanreroll
Comment #14
larowlanmerge cruft
Comment #16
larowlanmore merge cruft
Comment #18
larowlanComment #20
larowlanComment #22
larowlanSorting looks to be different on bot to local, test passes there
Comment #24
larowlanComment #26
larowlan