Problem/motivation
- MailInterface defines format() and send(). It is a common requirement to use two different implementations for those two methods, see #1135262: drupal_mail() should support using different MailSystemInterface classes for format() and mail(), e.g. format it as a MIME mail and set it out using one of the many mail as a service providers or SMTP.
- The construction of the used mail system implementation is hardcoded and can not be changed.
- The mailsystem module in 7.x currently circuments this limitation
Proposed solution
Move the logic in drupal_mail_system() to a service, keep the function as a wrapper. Then a module like mailsystem can replace the factory and implement something like the following pattern to work around the core limitation in a clean way:
$mail = new MailAdapter($format_mail, $send_mail);
$format_mail and $send_mail could be instantiated separately based on specific configuration, MailAdapter would then forward the calls accordingly.
User interface changes
None.
API changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | mailfactory-1889644-13.patch | 10.01 KB | berdir |
| #10 | mailfactory-1889644-10.patch | 9.86 KB | berdir |
| #7 | mailfactory-1889644-7.patch | 9.85 KB | berdir |
| #7 | mailfactory-1889644-7-interdiff.txt | 6.37 KB | berdir |
| #2 | mailfactory-1889644-2.patch | 9.74 KB | berdir |
Comments
Comment #1
oadaeh commentedIt sounds like you're referring to #1135262: drupal_mail() should support using different MailSystemInterface classes for format() and mail() and maybe #1089956: Provide Administrative UI and Developers API for safely setting the mail_system variable..
I'm thinking, at this point, those two are probably out of scope for 8.x.
Comment #2
berdirThis is the minimal implementation that doesn't introduce any API changes.
Completely untested :)
Will update the issue summary to explain why this is useful.
Comment #3
berdirUpdating title for the updated focus of this issue
Comment #4
dawehnerDo we still want to have a Drupal::static? All you probably need is the property on the factory object ... Hopefully we don't consider drupal_static_reset('drupal_mail_system') as an API.
Yes this is just moved, but that is kind of a redundant information as it is part of the interface. There you seem to have way less detailed descriptions.
Additional empty line and whitespace :p
Comment #5
oadaeh commentedResetting @Berdir's title change.
Comment #7
berdirThanks for the review.
- Removed the drupal_static(), that was a left-over
- Changed the Mail Factory to store the config object and not the actual configuration, that allows to change it while the factory is already instantiated
- Added the missing return in drupal_mail_system(). Going to be hard without that :p
- Moved the format documentation to MailInterface::format(), removed the mail part, not really relevant for either the interface or the factory to document what the default implementation is and does?
Comment #8
dawehnerThis looks really good for me.
That was just an implementation detail
Comment #9
alexpottThe patch looks good to me.
Needs a reroll
Comment #10
berdirReally? ;)
mail.inc didn't change in *5 month* before that config() stuff ;)
Comment #11
berdirJust conflicted due to config()/Drupal::config() in the removed code. So I think it's ok to move it back to RTBC.
Comment #12
dawehner+1
Theoretically we just add a "\" here :(
Needs docs :(
Comment #13
berdirFixed those docs.
Comment #14
dawehnerThanks
Comment #15
alexpottCommitted 4d783b7 and pushed to 8.x. Thanks!
Let's can a change notice to announce the new possibilities this patch permits.
Comment #16
berdirCreated https://drupal.org/node/2073215.
Comment #17.0
(not verified) commentedUpdate issue summary