mailsystem.theme.inc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file
  4. * The theme system, which controls the output of email messages.
  5. */
  6. /**
  7. * Implements hook_theme_registry_alter().
  8. */
  9. function mailsystem_theme_theme_registry_alter(&$theme_registry) {
  10. global $theme_key;
  11. static $recursion_prevention = FALSE;
  12. // Prevent recursive execution.
  13. if ($recursion_prevention) {
  14. return;
  15. }
  16. $recursion_prevention = TRUE;
  17. $mailsystem_theme = mailsystem_get_mail_theme();
  18. // Only take action if the mailsystem theme is not the current theme.
  19. if ($mailsystem_theme != $theme_key) {
  20. $themes = list_themes();
  21. // Get the mailsystem theme to be used for rendering emails.
  22. if (isset($themes[$mailsystem_theme])) {
  23. $theme = clone $themes[$mailsystem_theme];
  24. if (isset($theme)) {
  25. // Establish variables for further processing.
  26. $base_theme = array();
  27. if (isset($theme->base_themes)) {
  28. foreach (array_keys($theme->base_themes) as $base) {
  29. $base_theme[$base] = clone $themes[$base];
  30. }
  31. }
  32. if (isset($theme->base_theme) && !isset($base_theme[$theme->base_theme])) {
  33. $base_theme[$theme->base_theme] = clone $themes[$theme->base_theme];
  34. }
  35. if (isset($theme->engine)) {
  36. $theme_engine = $theme->engine;
  37. }
  38. // Include template files to let _theme_load_registry add preprocess
  39. // functions.
  40. include_once(drupal_get_path('theme', $theme->name) . '/template.php');
  41. foreach ($base_theme as $base) {
  42. include_once(drupal_get_path('theme', $base->name) . '/template.php');
  43. }
  44. // Get the theme_registry cache.
  45. $cache = _theme_load_registry($theme, $base_theme, $theme_engine);
  46. // Change the registry for hooks with a 'mail theme' element.
  47. foreach ($theme_registry as $name => $hook) {
  48. if (!empty($hook['mail theme'])) {
  49. if (isset($cache[$name])) {
  50. $cache[$name]['includes'][] = drupal_get_path('theme', $theme->name) . '/template.php';
  51. foreach ($base_theme as $base) {
  52. $cache[$name]['includes'][] = drupal_get_path('theme', $base->name) . '/template.php';
  53. }
  54. // Change the current registry for the new record.
  55. $theme_registry[$name] = $cache[$name];
  56. }
  57. // Look for template suggestions.
  58. foreach ($cache as $cache_name => $cache_hook) {
  59. if (strpos($cache_name, $name . '__') !== FALSE) {
  60. $cache_hook['includes'][] = drupal_get_path('theme', $theme->name) . '/template.php';
  61. foreach ($base_theme as $base) {
  62. $cache_hook['includes'][] = drupal_get_path('theme', $base->name) . '/template.php';
  63. }
  64. // Change the current registry for the new record.
  65. $theme_registry[$cache_name] = $cache_hook;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. $recursion_prevention = FALSE;
  74. }