From feaabe2bcd541db03337fbcef14bda37500a6bca Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 20 Nov 2014 10:31:25 +0000 Subject: [PATCH] Issue #2358993 by rpayanm, JeroenT: Remove usage of drupal_mail_system() --- core/includes/mail.inc | 11 ++++++----- core/lib/Drupal/Core/Mail/MailManagerInterface.php | 12 +++++++----- .../modules/simpletest/src/Tests/MailCaptureTest.php | 6 +++--- core/modules/system/src/Tests/Mail/MailTest.php | 2 +- core/modules/system/system.api.php | 4 ++-- core/modules/user/user.module | 4 ++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/core/includes/mail.inc b/core/includes/mail.inc index 5f5ec5312e0..b240421b136 100644 --- a/core/includes/mail.inc +++ b/core/includes/mail.inc @@ -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. diff --git a/core/lib/Drupal/Core/Mail/MailManagerInterface.php b/core/lib/Drupal/Core/Mail/MailManagerInterface.php index 89916c1d614..50645ab388a 100644 --- a/core/lib/Drupal/Core/Mail/MailManagerInterface.php +++ b/core/lib/Drupal/Core/Mail/MailManagerInterface.php @@ -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 diff --git a/core/modules/simpletest/src/Tests/MailCaptureTest.php b/core/modules/simpletest/src/Tests/MailCaptureTest.php index e8999a4d9c0..00b4be8cbfe 100644 --- a/core/modules/simpletest/src/Tests/MailCaptureTest.php +++ b/core/modules/simpletest/src/Tests/MailCaptureTest.php @@ -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'); } diff --git a/core/modules/system/src/Tests/Mail/MailTest.php b/core/modules/system/src/Tests/Mail/MailTest.php index 78ebf249814..26cc34f854c 100644 --- a/core/modules/system/src/Tests/Mail/MailTest.php +++ b/core/modules/system/src/Tests/Mail/MailTest.php @@ -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. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 4e98a643d40..1856f9aef1c 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -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 diff --git a/core/modules/user/user.module b/core/modules/user/user.module index bc0e15c01ab..31d7054bbc3 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -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.