Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/dds_sendgrid / dds_sendgrid.module
Size: Mime:
<?php

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Site\Settings;

/**
 * Implements hook_help().
 */
function dds_sendgrid_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.dds_sendgrid':
      return 'API module, allows usage of SendGrid\'s V3 API, also adds a mail plugin for the mailsystem to use.';
  }
}

/**
 * Implements hook_mail().
 */
function dds_sendgrid_mail($key, &$message, $params) {
  $message['module'] = 'dds_sendgrid';
  $message['key'] = $key;
  $message['subject'] = $params['subject'];
  $message['body'] = [];
  $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
  if (isset($params['body'])) {
    $message['body'] = explode(
      Settings::get('sendgrid.mail_line_endings', PHP_EOL) . Settings::get('sendgrid.mail_line_endings', PHP_EOL),
      $params['body']
    );
  }
  if (isset($params['sendgrid']['include_test_attachment']) && (bool)$params['sendgrid']['include_test_attachment']) {
    /** @var \Drupal\Core\File\FileSystem $file_system */
    $file_system = \Drupal::service('file_system');
    $message['attachments'][] = $file_system->realpath('core/misc/druplicon.png');
  }
  if (isset($params['Reply-To']) && !empty($params['Reply-To'])) {
    $message['headers']['Reply-To'] = $params['Reply-To'];
  }
}