3 namespace Drupal\webprofiler\Mail;
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Config\ConfigFactoryInterface;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\Core\Logger\LoggerChannelFactoryInterface;
9 use Drupal\Core\Mail\MailManagerInterface;
10 use Drupal\Core\Plugin\DefaultPluginManager;
11 use Drupal\Core\StringTranslation\StringTranslationTrait;
12 use Drupal\Core\StringTranslation\TranslationInterface;
13 use Drupal\webprofiler\DataCollector\MailDataCollector;
16 * Class MailManagerWrapper
18 class MailManagerWrapper extends DefaultPluginManager implements MailManagerInterface {
20 use StringTranslationTrait;
23 * @var \Drupal\webprofiler\DataCollector\MailDataCollector
25 private $dataCollector;
28 * @var \Drupal\Core\Mail\MailManagerInterface
35 * @var \Drupal\Core\Config\ConfigFactoryInterface
37 protected $configFactory;
42 * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
44 protected $loggerFactory;
47 * List of already instantiated mail plugins.
51 protected $instances = array();
54 * Constructs the MailManager object.
56 * @param \Traversable $namespaces
57 * An object that implements \Traversable which contains the root paths
58 * keyed by the corresponding namespace to look for plugin implementations.
59 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
60 * Cache backend instance to use.
61 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
62 * The module handler to invoke the alter hook with.
63 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
64 * The configuration factory.
65 * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
66 * The logger channel factory.
67 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
68 * The string translation service.
69 * @param \Drupal\Core\Mail\MailManagerInterface $mailManager
70 * @param \Drupal\webprofiler\DataCollector\MailDataCollector $dataCollector
72 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory, TranslationInterface $string_translation, MailManagerInterface $mailManager, MailDataCollector $dataCollector) {
73 parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Mail\MailInterface', 'Drupal\Core\Annotation\Mail');
74 $this->alterInfo('mail_backend_info');
75 $this->setCacheBackend($cache_backend, 'mail_backend_plugins');
76 $this->configFactory = $config_factory;
77 $this->loggerFactory = $logger_factory;
78 $this->stringTranslation = $string_translation;
79 $this->dataCollector = $dataCollector;
80 $this->mailManager = $mailManager;
86 public function mail($module, $key, $to, $langcode, $params = array(), $reply = NULL, $send = TRUE) {
87 $message = $this->mailManager->mail($module, $key, $to, $langcode, $params, $reply, $send);
89 $instance = $this->mailManager->getInstance(['module' => $module, 'key' => $key]);
90 $this->dataCollector->addMessage($message, $instance);