Created
May 20, 2015 21:05
-
-
Save mootari/e2bab2a75a96f8828d1e to your computer and use it in GitHub Desktop.
Preprocessing for theme hook suggestions. #drupal #theme
This file contains 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 | |
/** | |
* Provides additional preprocess hooks for theme hook suggestions. | |
*/ | |
function _THEME_process_hooks(&$vars, $process = 'preprocess', $hooks = null) { | |
$prefix = '_THEME'; | |
if(is_null($hooks)) { | |
$hooks = $vars['theme_hook_suggestions']; | |
} | |
static $static_fast; | |
if(is_null($static_fast)) { | |
$static_fast['functions'] = &drupal_static(__FUNCTION__, array()); | |
} | |
foreach($hooks as $hook) { | |
if(!isset($static_fast['functions'][$hook][$process])) { | |
$function = $prefix . '_' . $process . '__' . $hook; | |
$static_fast['functions'][$hook][$process] = function_exists($function) ? $function : false; | |
} | |
if($static_fast['functions'][$hook][$process]) { | |
$static_fast['functions'][$hook][$process]($vars); | |
} | |
} | |
} | |
/** | |
* Provide additional theme_hook_suggestions for node types based | |
* on viewmodes | |
*/ | |
function THEME_preprocess_node(&$vars) { | |
$type = $vars['type']; | |
$view_mode = $vars['view_mode'] ? $vars['view_mode'] : 'full'; | |
$vars['theme_hook_suggestions'] = array( | |
"node__{$type}", | |
"node__{$type}__{$view_mode}", | |
); | |
_THEME_process_hooks($vars, 'preprocess'); | |
} | |
function _THEME_preprocess_node__page(&$vars) { | |
// Do stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment