You are here

function htmlmail_theme in HTML Mail 8

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

Implements hook_theme().

2 string references to 'htmlmail_theme'
HtmlMailConfigurationForm::buildForm in src/Form/HtmlMailConfigurationForm.php
Defines the settings form for HTML Mail.
HtmlMailHelper::getSelectedTheme in src/Helper/HtmlMailHelper.php
Returns the selected theme to use for outgoing emails.

File

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

Code

function htmlmail_theme($existing, $type, $theme, $path) {
  $items = [];
  $module_path = \Drupal::service('module_handler')
    ->getModule(HtmlMailHelper::HTMLMAIL_MODULE_NAME)
    ->getPath();
  $pattern = '/^,
  .*\\.html\\.twig$/';
  $files = file_scan_directory('modules', $pattern, [
    'key' => 'name',
  ]);
  if ($theme = HtmlMailHelper::getSelectedTheme()) {
    $theme_path = \Drupal::service('theme_handler')
      ->getTheme($theme)
      ->getPath();
    $files = array_merge($files, file_scan_directory($theme_path, $pattern, [
      'key' => 'name',
    ]));
  }
  else {
    $theme_path = $module_path . '/templates';
  }
  ksort($files);
  foreach ($files as $file) {
    $path = dirname($file->uri);
    $template = substr($file->name, 0, -5);
    $suggestion = str_replace('--', '__', $template);
    $items[$suggestion] = [
      'variables' => [
        'message' => [],
      ],
      'template' => $template,
      'path' => $path,
      'theme path' => $theme_path,
    ];
  }
  return $items;
}