Issue #2358993 by rpayanm, JeroenT: Remove usage of drupal_mail_system()

8.0.x
Alex Pott 2014-11-20 10:31:25 +00:00
parent bbd92baf3f
commit feaabe2bcd
6 changed files with 21 additions and 18 deletions

View File

@ -14,10 +14,10 @@ use Drupal\Core\Mail\MailFormatHelper;
* and possibly email headers) and the replacement values to use in the
* appropriate places in the template. Processed email templates are
* requested from hook_mail() from the module sending the email. Any module
* can modify the composed email message array using hook_mail_alter().
* Finally drupal_mail_system()->mail() sends the email, which can
* be reused if the exact same composed email is to be sent to multiple
* recipients.
* can modify the composed email message array using hook_mail_alter(). Finally
* \Drupal::service('plugin.manager.mail')->getInstance()->mail() sends the
* email, which can be reused if the exact same composed email is to be sent to
* multiple recipients.
*
* Finding out what language to send the email with needs some consideration.
* If you send email to a user, her preferred language should be fine, so
@ -101,7 +101,8 @@ use Drupal\Core\Mail\MailFormatHelper;
* @param string|null $reply
* Optional email address to be used to answer.
* @param bool $send
* If TRUE, drupal_mail() will call drupal_mail_system()->mail() to deliver
* If TRUE, drupal_mail() will call
* \Drupal::service('plugin.manager.mail')->getInstance()->mail() to deliver
* the message, and store the result in $message['result']. Modules
* implementing hook_mail_alter() may cancel sending by setting
* $message['send'] to FALSE.

View File

@ -22,8 +22,9 @@ interface MailManagerInterface extends PluginManagerInterface {
* appropriate places in the template. Processed email templates are requested
* from hook_mail() from the module sending the email. Any module can modify
* the composed email message array using hook_mail_alter(). Finally
* drupal_mail_system()->mail() sends the email, which can be reused if the
* exact same composed email is to be sent to multiple recipients.
* \Drupal::service('plugin.manager.mail')->mail() sends the email, which can
* be reused if the exact same composed email is to be sent to multiple
* recipients.
*
* Finding out what language to send the email with needs some consideration.
* If you send email to a user, her preferred language should be fine, so use
@ -108,9 +109,10 @@ interface MailManagerInterface extends PluginManagerInterface {
* Optional email address to be used to answer.
* @param bool $send
* If TRUE, \Drupal::service('plugin.manager.mail')->mail() will call
* drupal_mail_system()->mail() to deliver the message, and store the result
* in $message['result']. Modules implementing hook_mail_alter() may cancel
* sending by setting $message['send'] to FALSE.
* \Drupal::service('plugin.manager.mail')->mail() to deliver the message,
* and store the result in $message['result']. Modules implementing
* hook_mail_alter() may cancel sending by setting $message['send'] to
* FALSE.
*
* @return string
* The $message array structure containing all details of the message. If

View File

@ -36,7 +36,7 @@ class MailCaptureTest extends WebTestBase {
$this->assertEqual(count($captured_emails), 0, 'The captured emails queue is empty.', 'Email');
// Send the email.
drupal_mail_system('simpletest', 'drupal_mail_test')->mail($message);
\Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'simpletest', 'key' => 'drupal_mail_test'))->mail($message);
// Ensure that there is one email in the captured emails array.
$captured_emails = $this->drupalGetMails();
@ -57,7 +57,7 @@ class MailCaptureTest extends WebTestBase {
'to' => $this->randomMachineName(32) . '@example.com',
'body' => $this->randomString(512),
);
drupal_mail_system('drupal_mail_test', $index)->mail($message);
\Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'drupal_mail_test', 'key' => $index))->mail($message);
}
// There should now be 6 emails captured.
@ -75,7 +75,7 @@ class MailCaptureTest extends WebTestBase {
// Send the last email again, so we can confirm that the
// drupalGetMails-filter correctly returns all emails with a given
// property/value.
drupal_mail_system('drupal_mail_test', $index)->mail($message);
\Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'drupal_mail_test', 'key' => $index))->mail($message);
$captured_emails = $this->drupalGetMails(array('id' => 'drupal_mail_test_4'));
$this->assertEqual(count($captured_emails), 2, 'All emails with the same id are returned when filtering by id.', 'Email');
}

View File

@ -39,7 +39,7 @@ class MailTest extends WebTestBase {
\Drupal::config('system.mail')->set('interface.default', 'test_php_mail_failure')->save();
// Get the default MailInterface class instance.
$mail_backend = drupal_mail_system('default', 'default');
$mail_backend = \Drupal::service('plugin.manager.mail')->getInstance(array('module' => 'default', 'key' => 'default'));
// Assert whether the default mail backend is an instance of the expected
// class.

View File

@ -305,8 +305,8 @@ function hook_contextual_links_plugins_alter(array &$contextual_links) {
*
* Email messages sent using functions other than drupal_mail() will not
* invoke hook_mail_alter(). For example, a contributed module directly
* calling the drupal_mail_system()->mail() or PHP mail() function
* will not invoke this hook. All core modules use drupal_mail() for
* calling the \Drupal::service('plugin.manager.mail')->mail() or PHP mail()
* function will not invoke this hook. All core modules use drupal_mail() for
* messaging, it is best practice but not mandatory in contributed modules.
*
* @param $message

View File

@ -1290,8 +1290,8 @@ function user_role_revoke_permissions($rid, array $permissions = array()) {
* language.
*
* @return
* The return value from drupal_mail_system()->mail(), if ends up being
* called.
* The return value from \Drupal::service('plugin.manager.mail')->mail(), if
* ends up being called.
*/
function _user_mail_notify($op, $account, $langcode = NULL) {
// By default, we always notify except for canceled and blocked.