As requested, I have modified the API of the Mail System module to support using one MailSystemInterface class for the format() method, and another for the mail() method. The Mail System module does this by dynamically writing a custom class and adding it to the registry.

It would only take a small change to support this in core without requiring such a monstrous hack.

Comments

pillarsdotnet’s picture

Status: Active » Needs review
StatusFileSize
new4.9 KB

Patch.

sun’s picture

Status: Needs review » Needs work
+++ b/includes/mail.inc
@@ -220,10 +234,13 @@ function drupal_mail($module, $key, $to, $language, $params = array(), $from = N
+function drupal_mail_system($module, $key, $method='format') {

@@ -232,15 +249,33 @@ function drupal_mail_system($module, $key) {
-  if (isset($configuration[$id])) {
+  if ( isset($configuration[$id])
+    && ( is_string($configuration[$id])
+      || ( is_array($configuration[$id])
+        && isset($configuration[$id][$method])
+      )
+    )
+  ) {
     $class = $configuration[$id];
   }
-  elseif (isset($configuration[$module])) {
+  elseif (isset($configuration[$module])
+    && ( is_string($configuration[$module])
+      || ( is_array($configuration[$module])
+        && isset($configuration[$module][$method])
+      )
+    )
+  ) {
     $class = $configuration[$module];

Various coding style issues. See http://drupal.org/coding-standards

+++ b/includes/mail.inc
@@ -232,15 +249,33 @@ function drupal_mail_system($module, $key) {
+  if (is_array($class)) {
+    if (empty($class[$method])) {
+      throw new Exception(t('The %mail_system variable does not specify a %interface class to use for the %method method.', array('%mail_system' => 'mail_system', '%interface' => 'MailSystemInterface', '%method' => $method)));
+    }
+    $class = $class[$method];
+  }

It looks like this patch tries to retain support for strings to some extent, but then again not.

For D8, if this patch is going to be considered, a decision needs to be made as to whether both data types are allowed, or whether all variables should be arrays for consistency.

Powered by Dreditor.

pillarsdotnet’s picture

Issue tags: +Needs backport to D7

@sun -- I don't understand how indenting two spaces for each added nested parenthesis is a violation of coding standards. Please explain.

And yes, I am trying to maintain backwards compatibility with the existing API, because I have hopes of this feature being backported to 7.x.

Therefore a string value (old API) indicates that the same class should be used for both methods, whereas an array value (new API) indicates a per-method class setting.

pillarsdotnet’s picture

Status: Needs work » Needs review
pillarsdotnet’s picture

StatusFileSize
new5.15 KB

Revised patch with more verbose logic that may possibly pass sun coding standards.

sun’s picture

Status: Needs review » Needs work

1) a) Missing spaces in function argument default value. b) Superfluous white-space in control structure conditions. c) The conditions should not be wrapped.

2) Whether this API change can be backported to D7 is a question that has to be deferred. For now, only a proper implementation for D8 matters. I'd like to hear feedback from others, but it likely means that we want to have consistent system variable values; i.e., all being arrays, no support for string values. Otherwise, modules that are trying to adjust these variables (and potentially variable values of other modules) would have to care for the different data types on their own all over the place. Ironically, this very Mail API had a very similar weirdness that allowed modules to set the mail body to a string or to an array, which was a major pain.

pillarsdotnet’s picture

Status: Needs work » Needs review
StatusFileSize
new5.16 KB

Missing spaces in function argument default value.

Okay, I was wondering about that. Fixed.

Superfluous white-space in control structure conditions. c) The conditions should not be wrapped.

Obviously you haven't looked at the updated patch in #5. That's okay. Ignore that one and look at the patch in #7 instead.

My eventual goal is to get the entirety of the Mail System module added to core. I have therefore been maintaining 8.x, 7.x, and 6.x branches of that module. The patch in this issue will help Mail System become core-worthy. If and when that happens, no module should ever have to directly modify the mail_system variable.

Whether this API change can be backported to D7 is a question that has to be deferred.

So you don't want any patches added to D8 with the intention of backporting to D7, because you think that D8 shouldn't care about backwards compatibility. I hope your opinion is not shared by other reviewers, especially those who have D8 checked out or installed anywhere.

pillarsdotnet’s picture

Issue tags: +Needs backport to D7
pillarsdotnet’s picture

@#6

The conditions should not be wrapped.

Perfect example of a sun coding standard that is not found anywhere in drupal coding standards.

pillarsdotnet’s picture

Issue tags: -Needs backport to D7

#7: drupal_mail_system-1135262-7.patch queued for re-testing.

pillarsdotnet’s picture

Issue tags: -Needs backport to D7

#7: drupal_mail_system-1135262-7.patch queued for re-testing.

pillarsdotnet’s picture

#7: drupal_mail_system-1135262-7.patch queued for re-testing.

pillarsdotnet’s picture

#7: drupal_mail_system-1135262-7.patch queued for re-testing.

pillarsdotnet’s picture

#7: drupal_mail_system-1135262-7.patch queued for re-testing.

dwightaspinwall’s picture

#7: drupal_mail_system-1135262-7.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, drupal_mail_system-1135262-7.patch, failed testing.

dwightaspinwall’s picture

Is this issue still relevant? If so, I'd be happy to re-roll the patch in #7.

yesct’s picture

next step, verify the issue still exists, write/update steps to reproduce

pelicani’s picture

Assigned: pillarsdotnet » pelicani

beginning to manually test

pelicani’s picture

it appears that the patch in #7 refers to the mail.inc file in the wrong location
the patch points to includes/mail.inc
but the current d8 has the file in core/includes/mail.inc

the coding standards also may be debated and we should review to make sure they are up to standard.

pelicani’s picture

StatusFileSize
new4.45 KB

I took the patch provided by @pillarsdotnet and applied it to the current mail.inc.
I copied and pasted the code exactly without any changes of my own.

The only unclear change is with the reference to 'MailSystemInterface' vs 'Drupal\Core\Mail\MailInterface'.
It is referenced in the examples and the comments.
I chose to use the MailSystemInterface as posted by @pillarsdotnet.

pelicani’s picture

Status: Needs work » Needs review

I think I should have changed the status.
changing status to needs review.

Gaelan’s picture

Issue tags: -Needs reroll

Removing 'needs reroll' tag.

oadaeh’s picture

Version: 8.x-dev » 9.x-dev
+++ b/core/includes/mail.inc
@@ -272,15 +289,44 @@ function drupal_mail_system($module, $key) {
+  do {
...
+++ b/core/includes/mail.inc
@@ -272,15 +289,44 @@ function drupal_mail_system($module, $key) {
+  } while (FALSE);

I'm betting this entire control structure will need to be redone.

I also don't think, at this late stage, it will make it into 8.x.

berdir’s picture

See also #1889644: Convert drupal_mail_system() to a MailFactory service to allow more flexible replacements, which does not directly resolve this but makes it much easier and less ugly to support this in mailsystem.module.

catch’s picture

Version: 9.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Needs review » Postponed

Ought to be possible with a bc layer.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for sharing your idea for improving Drupal.

We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

berdir’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Lets close this, mailsystem supports this and the core system will be replaced with something that looks very different eventually.