class MandrillTestService in Mandrill 8
Test Mandrill service.
Hierarchy
- class \Drupal\mandrill\MandrillService implements MandrillServiceInterface
- class \Drupal\mandrill\MandrillTestService
Expanded class hierarchy of MandrillTestService
1 string reference to 'MandrillTestService'
1 service uses MandrillTestService
File
- src/
MandrillTestService.php, line 8
Namespace
Drupal\mandrillView source
class MandrillTestService extends MandrillService {
/**
* {@inheritdoc}
*/
protected function handleSendResponse($response, $message) {
if (isset($response['status'])) {
// There was a problem sending the message.
return FALSE;
}
foreach ($response as $result) {
// Allow other modules to react based on a send result.
\Drupal::moduleHandler()
->invokeAll('mandrill_mailsend_result', [
$result,
], [
$message,
]);
switch ($result['status']) {
case "error":
case "invalid":
case "rejected":
return FALSE;
}
}
return TRUE;
}
/**
* Abstracts sending of messages using PHP's built-in mail() function
* instead of Mandrill's sending API.
*
* @param array $message
* A message array formatted for Mandrill's sending API.
*
* @return bool
* TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
*/
public function send($message) {
if (\Drupal::config('system.mail')
->get('interface.default') === 'test_mail_collector') {
$captured_emails = \Drupal::state()
->get('system.test_mail_collector') ?: [];
$captured_emails[] = $message;
\Drupal::state()
->set('system.test_mail_collector', $captured_emails);
return TRUE;
}
return parent::send($message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MandrillService:: |
protected | property | The Config Factory service. | |
MandrillService:: |
protected | property | The Logger Factory service. | |
MandrillService:: |
protected | property | The Mandrill API service. | |
MandrillService:: |
public | function |
Get the mail systems defined in the mail system module. Overrides MandrillServiceInterface:: |
|
MandrillService:: |
public | function |
Helper to generate an array of recipients. Overrides MandrillServiceInterface:: |
|
MandrillService:: |
public | function | Constructs the service. | |
MandrillTestService:: |
protected | function |
Response handler for sent messages. Overrides MandrillService:: |
|
MandrillTestService:: |
public | function |
Abstracts sending of messages using PHP's built-in mail() function
instead of Mandrill's sending API. Overrides MandrillService:: |