View source
<?php
namespace Drupal\webprofiler\Mail;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Mail\MailManagerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\webprofiler\DataCollector\MailDataCollector;
class MailManagerWrapper extends DefaultPluginManager implements MailManagerInterface {
use StringTranslationTrait;
private $dataCollector;
private $mailManager;
protected $configFactory;
protected $loggerFactory;
protected $instances = [];
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory, TranslationInterface $string_translation, MailManagerInterface $mailManager, MailDataCollector $dataCollector) {
parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\\Core\\Mail\\MailInterface', 'Drupal\\Core\\Annotation\\Mail');
$this
->alterInfo('mail_backend_info');
$this
->setCacheBackend($cache_backend, 'mail_backend_plugins');
$this->configFactory = $config_factory;
$this->loggerFactory = $logger_factory;
$this->stringTranslation = $string_translation;
$this->dataCollector = $dataCollector;
$this->mailManager = $mailManager;
}
public function mail($module, $key, $to, $langcode, $params = [], $reply = NULL, $send = TRUE) {
$message = $this->mailManager
->mail($module, $key, $to, $langcode, $params, $reply, $send);
$instance = $this->mailManager
->getInstance([
'module' => $module,
'key' => $key,
]);
$this->dataCollector
->addMessage($message, $instance);
return $message;
}
public function getInstance(array $options) {
return $this->mailManager
->getInstance($options);
}
}