Skip to content

Instantly share code, notes, and snippets.

@rjpeter2
Last active December 15, 2015 20:59
Show Gist options
  • Save rjpeter2/5322827 to your computer and use it in GitHub Desktop.
Save rjpeter2/5322827 to your computer and use it in GitHub Desktop.
Have Drupal find your modules tpl overrides.
<?php
// Create a variable to store the path to this module
define('MY_MODULE_PATH', drupal_get_path('module', 'pricing_calculator'));
/**
* Implements hook_theme_registry_alter().
*
* Makes Drupal find our page template file.
* Found this at: http://drupal.org/node/715160
*/
function pricing_calculator_theme_registry_alter(&$theme_registry) {
$theme_registry_copy = $theme_registry;
_theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'hp_cloud_tile_site', MY_MODULE_PATH);
$theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
// A list of templates the module will provide templates for
$hooks = array('page');
foreach ($hooks as $h) {
// Add the key 'theme paths' if it doesn't exist in this theme's registry
if (!isset($theme_registry[$h]['theme paths'])) {
$theme_registry[$h]['theme paths'] = array();
}
//Shift this module's directory to the top of the theme path list
if(is_array($theme_registry[$h]['theme paths'])) {
$first_element = array_shift($theme_registry[$h]['theme paths']);
if ($first_element) {
array_unshift($theme_registry[$h]['theme paths'], $first_element, MY_MODULE_PATH);
} else {
array_unshift($theme_registry[$h]['theme paths'], MY_MODULE_PATH);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment