You are here

mailgun.module in Mailgun 8

Same filename and directory in other branches
  1. 7 mailgun.module

Contains mailgun.module.

File

mailgun.module
View source
<?php

/**
 * @file
 * Contains mailgun.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function mailgun_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the mailgun module.
    case 'help.page.mailgun':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Enables site to send emails using Mailgun.com') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function mailgun_theme($existing, $type, $theme, $path) {
  return [
    'mailgun' => [
      'variables' => [
        'message' => [],
      ],
      'mail theme' => TRUE,
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function mailgun_theme_suggestions_mailgun(array $variables) {
  $suggestions = [];
  $suggestions[] = 'mailgun__' . $variables['message']['module'];
  $suggestions[] = 'mailgun__' . $variables['message']['key'];
  $suggestions[] = 'mailgun__' . $variables['message']['module'] . '__' . $variables['message']['key'];
  return $suggestions;
}

/**
 * Prepares variables for mailgun templates.
 *
 * Default template: mailgun.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - message: An associative array containing the message array.
 *   - body: The processed body.
 */
function template_preprocess_mailgun(array &$variables) {
  $variables['subject'] = $variables['message']['subject'];
  $variables['body'] = $variables['message']['body'];
}

/**
 * Implements hook_mail().
 */
function mailgun_mail($key, &$message, $params) {
  switch ($key) {
    case 'test_form_email':
      $message['body'] = $message['params']['body'];
      $message['subject'] = $message['params']['subject'];
      if (isset($params['cc'])) {
        $message['headers']['Cc'] = $params['cc'];
      }
      if (isset($params['bcc'])) {
        $message['headers']['Bcc'] = $params['bcc'];
      }
      break;
  }
}

Functions

Namesort descending Description
mailgun_help Implements hook_help().
mailgun_mail Implements hook_mail().
mailgun_theme Implements hook_theme().
mailgun_theme_suggestions_mailgun Implements hook_theme_suggestions_HOOK().
template_preprocess_mailgun Prepares variables for mailgun templates.