sendgrid_integration-8.x-1.x-dev/sendgrid_integration.module
sendgrid_integration.module
<?php
/**
* @file
* Main module file for SendGrid Integration.
*
* Provides module configuration and help functionality.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Site\Settings;
// Ludwig module integration.
if (\Drupal::hasService('ludwig.require_once')) {
$ludwig_require_once = \Drupal::service('ludwig.require_once');
$ludwig_require_once->requireOnce('starkbank/ecdsa', 'src/ellipticcurve.php', dirname(__FILE__));
}
/**
* Implements hook_help().
*/
function sendgrid_integration_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_name) {
case 'help.page.sendgrid_integration':
$output .= '<h3>' . \Drupal::translation()->translate('About') . '</h3>';
$output .= '<p>' . \Drupal::translation()
->translate('Module provides own implementation of MailSystemIntegration, replacing the default implementation and uses SendGrid Web API instead.') . '</p>';
}
return $output;
}
/**
* Implements hook_mail().
*/
function sendgrid_integration_mail($key, &$message, $params) {
$message['module'] = 'sendgrid_integration';
$message['key'] = $key;
$message['subject'] = $params['subject'];
$message['body'] = explode(
Settings::get('mail_line_endings', PHP_EOL) . Settings::get('mail_line_endings', PHP_EOL),
$params['body']
);
if (isset($params['include_test_attachment'])) {
$message['attachments'][] = \Drupal::service('file_system')
->realpath('core/misc/druplicon.png');
}
if (isset($params['Reply-To']) && !empty($params['Reply-To'])) {
$message['headers']['Reply-To'] = $params['Reply-To'];
}
else {
if (isset($params['reply_to']) && !empty($params['reply_to'])) {
$message['headers']['Reply-To'] = $params['reply_to'];
}
}
}
