Skip to content

Commit

Permalink
Simplified handling of config in driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanjfshaw committed Feb 12, 2018
1 parent 9115fef commit 5413e26
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions src/Drupal/DrupalMailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,31 @@ class DrupalMailManager implements DrupalMailManagerInterface {
* @var \Drupal\Driver\DriverInterface
*/
protected $driver;

/**
* The name or config array of the initial mail backend.
*
* @var mixed
*/
protected $initialMailBackend;

public function __construct(DriverInterface $driver) {
$this->driver = $driver;
}

/**
* Replace the initial mail backend with the test mail backend.
*/
protected function enableTestMailBackend() {
if (is_null($this->initialMailBackend)) {
$this->initialMailBackend = $this->driver->getMailBackend();
}
// @todo Use a collector that supports html after D#2223967 lands.
$this->driver->setMailBackend('test_mail_collector');
}

/**
* Restore the initial mail backend.
*/
protected function restoreInitialMailBackend() {
$this->driver->setMailBackend($this->initialMailBackend);
}

/**
* {@inheritdoc}
*/
public function startCollectingMail() {
$this->enableTestMailBackend();
$this->driver->startCollectingMail();
$this->clearMail();
}

/**
* {@inheritdoc}
*/
public function stopCollectingMail() {
$this->restoreInitialMailBackend();
$this->driver->stopCollectingMail();
}

/**
* {@inheritdoc}
*/
public function enableMail() {
$this->restoreInitialMailBackend();
$this->stopCollectingMail();
}

/**
Expand Down

0 comments on commit 5413e26

Please sign in to comment.