Last active
November 2, 2019 02:09
-
-
Save robdecker/6ff5467bacf8838d6bd3 to your computer and use it in GitHub Desktop.
[Using template (.tpl.php) files in your own module] See https://www.drupal.org/node/715160 #d7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_theme_registry_alter(). | |
*/ | |
function mymodule_theme_registry_alter(&$theme_registry) { | |
// Defined path to the current module. | |
$module_path = drupal_get_path('module', 'mymodule'); | |
// Find all .tpl.php files in this module's folder recursively. | |
$template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path); | |
// Iterate through all found template file objects. | |
foreach ($template_file_objects as $key => $template_file_object) { | |
// If the template has not already been overridden by a theme. | |
if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) { | |
// Alter the theme path and template elements. | |
$theme_registry[$key]['theme path'] = $module_path; | |
$theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object); | |
$theme_registry[$key]['type'] = 'module'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment