You are here

devel_mail_logger.module in Devel Mail Logger 8

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

File

devel_mail_logger.module
View source
<?php

/**
 * @file
 * Contains devel_mail_logger.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Utility\Html;

/**
 * Implements hook_help().
 */
function devel_mail_logger_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.devel_mail_logger') {
    $readme_content = file_get_contents(__DIR__ . '/README.md');
    if (\Drupal::moduleHandler()
      ->moduleExists('markdown')) {

      // Use the Markdown filter to render the README.
      $filter_manager = \Drupal::service('plugin.manager.filter');
      $markdown_config = \Drupal::configFactory()
        ->get('markdown.settings')
        ->getRawData();
      $markdown_settings = [
        'settings' => $markdown_config,
      ];

      /** @var \Drupal\markdown\Plugin\Filter\MarkdownFilterInterface $filter */
      $filter = $filter_manager
        ->createInstance('markdown', $markdown_settings);
      return $filter
        ->process($readme_content, 'en');
    }
    else {
      return [
        '#type' => 'html_tag',
        '#tag' => 'pre',
        '#value' => $readme_content,
      ];
    }
  }
}

/**
 * Implements hook_mail().
 */
function devel_mail_logger_mail($key, &$message, $params) {
  $options = [
    'langcode' => $message['langcode'],
  ];
  switch ($key) {
    case 'send_test':
      $message['from'] = \Drupal::config('system.site')
        ->get('mail');
      $message['subject'] = t('Your mail subject Here: @subject', [
        '@subject' => $params['subject'],
      ], $options);
      $message['body'][] = Html::escape($params['message']);
      break;
  }
}

Functions

Namesort descending Description
devel_mail_logger_help Implements hook_help().
devel_mail_logger_mail Implements hook_mail().