Skip to content

Instantly share code, notes, and snippets.

@siefca
Forked from cafuego/Magic render var from taxo parent
Last active December 14, 2015 09:59
Show Gist options
  • Save siefca/5069092 to your computer and use it in GitHub Desktop.
Save siefca/5069092 to your computer and use it in GitHub Desktop.
<?php
function mytheme_alpha_preprocess_node(&$vars) {
$node = $vars['node'];
if (isset($vars['field_topic'][0]['tid'])) {
$parents = taxonomy_get_parents($vars['field_topic'][0]['tid']);
$top_parent = array_shift($parents);
$vars['topic'] = field_view_value('node', $node, 'field_topic', array(
'tid' => $top_parent->tid, 'label' => 'hidden'));
$vars['topic_rendered'] = theme('field', array('element' => array (
'#title' => $vars['content']['field_topic']['#title'],
'#field_name' => 'field_topic', /* imitate source name too */
'#field_type' => $vars['content']['field_topic']['#field_type'],
'#entity_type' => $vars['content']['field_topic']['#entity_type'],
'#bundle' => $vars['content']['field_topic']['#bundle'],
'#label_display' => 'hidden',
'#items' => array('0' => array(
'tid' => $top_parent->tid,
'taxonomy_term' => &$top_parent
)),
'0' => &$vars['topic'],
)));
unset($parents, $top_parent);
}
else {
$vars['topic'] = array();
$vars['topic_rendered'] = array();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment