Created
March 28, 2014 01:05
-
-
Save m7v/9822836 to your computer and use it in GitHub Desktop.
Define your own preprocesses and templates for nodes.
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
function spaint_preprocess_node(&$variables, $hook) { | |
global $theme; | |
global $language; | |
$variables['node']->field_image[LANGUAGE_NONE][0]['title'] = $variables['title_field'][$language->language][0]['value']; | |
// Initialize templates architecture. | |
if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) { | |
$variables['classes_array'][] = 'node-full'; | |
} | |
$node = $variables['node']; | |
$build_mode_for_preprocess = str_replace('-', '_', $variables['view_mode']); | |
$variables['theme_hook_suggestions'][] = 'node__' . $variables['view_mode']; | |
$variables['theme_hook_suggestions'][] = 'node__' . $node->type . '_' . $variables['view_mode']; | |
// Defines the priority of calling preprocess functions for specific node type & view modes. | |
// Note: priority is calculated in reverse mode. | |
$preprocess = array( | |
$theme . '_preprocess_node__' . $node->type, | |
$theme . '_preprocess_node__' . $build_mode_for_preprocess, | |
$theme . '_preprocess_node__' . $node->type . '_' . $build_mode_for_preprocess, | |
); | |
foreach (array_reverse($preprocess) as $function) { | |
if (function_exists($function)) { | |
$function($variables, $hook); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment