Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Mail / Plugin / Mail / TestMailCollector.php
1 <?php
2
3 namespace Drupal\Core\Mail\Plugin\Mail;
4
5 use Drupal\Core\Mail\MailInterface;
6
7 /**
8  * Defines a mail backend that captures sent messages in the state system.
9  *
10  * This class is for running tests or for development.
11  *
12  * @Mail(
13  *   id = "test_mail_collector",
14  *   label = @Translation("Mail collector"),
15  *   description = @Translation("Does not send the message, but stores it in Drupal within the state system. Used for testing.")
16  * )
17  */
18 class TestMailCollector extends PhpMail implements MailInterface {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function mail(array $message) {
24     $captured_emails = \Drupal::state()->get('system.test_mail_collector') ?: [];
25     $captured_emails[] = $message;
26     \Drupal::state()->set('system.test_mail_collector', $captured_emails);
27
28     return TRUE;
29   }
30
31 }