Extend Drupal's default Taxonomy terms overview table listing
Sharing something I recently needed to do.
I wanted to add a new column to the default Drupal's Taxonomy term listing page that provides a link to a DraggableViews (receives term ID from contextual filter) for sorting nodes.
This guide will show you briefly on how to make use of hook_theme().
See screenshot below for the final result.
In your custom module, add the following code:
/**<br> * Implements hook_form_FORM_ID_alter().<br> */<br>function YOUR_MODULE_form_taxonomy_overview_terms_alter(&$form, &$form_state, $form_id) {<br> // Add custom theme wrapper.<br> array_unshift($form['#theme'], 'YOUR_MODULE_taxonomy_overview_terms');<br>}<p>/**<br> * Implements hook_theme().<br> */<br>function YOUR_MODULE_theme() {<br> return array(<br> 'YOUR_MODULE_taxonomy_overview_terms' => array(<br> 'render element' => 'form',<br> ),<br> );<br>}</p><p>function theme_YOUR_MODULE_taxonomy_overview_terms($vars) {<br> ...<br> // Codes from theme_taxonomy_overview_terms()<br> <br> foreach (element_children($form) as $key) {<br> if (isset($form[$key]['#term'])) {<br> $term = &$form[$key];</p><p> $row = array();<br> $row[] = (isset($term['#term']['depth']) && $term['#term']['depth'] > 0 ? theme('indentation', array('size' => $term['#term']['depth'])) : '') . drupal_render($term['view']);<br> if ($form['#parent_fields']) {<br> $term['tid']['#attributes']['class'] = array('term-id');<br> $term['parent']['#attributes']['class'] = array('term-parent');<br> $term['depth']['#attributes']['class'] = array('term-depth');<br> $row[0] .= drupal_render($term['parent']) . drupal_render($term['tid']) . drupal_render($term['depth']);<br> }<br> $term['weight']['#attributes']['class'] = array('term-weight');<br> $row[] = drupal_render($term['weight']);<br> $row[] = drupal_render($term['edit']);<br> $row[] = (isset($term['#term']['tid'])) ? l(t('sort'), 'blablabla/' . $term['#term']['tid']) : '';<br> $row = array('data' => $row);<br> $rows[$key] = $row;<br> }<br> }</p><p> ...<br>}</p>
Hope this short and simple snippet helps someone out there :)
Tags: drupaldrupal 7taxonomythemetermsvocabularyhookdraggableviews