You are here

function template_preprocess_htmlmail in HTML Mail 8

Same name and namespace in other branches
  1. 8.3 htmlmail.module \template_preprocess_htmlmail()
  2. 8.2 htmlmail.module \template_preprocess_htmlmail()
  3. 6.2 htmlmail.module \template_preprocess_htmlmail()
  4. 6 htmlmail.module \template_preprocess_htmlmail()
  5. 7.2 htmlmail.module \template_preprocess_htmlmail()
  6. 7 htmlmail.module \template_preprocess_htmlmail()

Process variables to format email messages.

See also

htmlmail.html.twig

File

./htmlmail.module, line 109
Default file for HTML Mail module.

Code

function template_preprocess_htmlmail(array &$variables) {
  $html_settings = \Drupal::config('htmlmail.settings');
  $module_handler = \Drupal::service('module_handler');
  $theme_handler = \Drupal::service('theme_handler');
  $variables['debug'] = $html_settings
    ->get('htmlmail_debug') ?: 0;
  $variables['theme'] = HtmlMailHelper::getSelectedTheme($variables);
  $variables['module_path'] = $module_handler
    ->getModule('htmlmail')
    ->getPath() . '/templates';
  if (empty($variables['theme'])) {
    $variables['theme'] = 'no theme';
    $variables['theme_path'] = $variables['module_path'];
  }
  else {
    $variables['theme_path'] = $theme_handler
      ->getTheme($variables['theme'])
      ->getPath() . '/templates';
  }
  global $base_url;
  $module = $variables['message']['module'];
  $key = $variables['message']['key'];
  $params = [
    trim($variables['message']['subject']),
    trim($variables['message']['body']),
  ];
  $variables['theme_url'] = $base_url . base_path() . $variables['theme_path'];
  $variables['message_id'] = $module . '_' . $key;
  $variables['module_template'] = "htmlmail--{$module}.html.twig";
  $variables['message_template'] = "htmlmail--{$module}--{$key}.html.twig";
  $variables['theme_html_exists'] = file_exists($variables['theme_path'] . '/htmlmail.html.twig');
  $variables['message_template_exists'] = file_exists("{$variables['theme_path']}/{$variables['message_template']}");
  $variables['module_template_exists'] = file_exists("{$variables['theme_path']}/{$variables['module_template']}");
  $variables['pre_formatted_params'] = print_r($params, 1);
}