Last active
December 10, 2015 20:18
-
-
Save benclark/4487411 to your computer and use it in GitHub Desktop.
Theme a series of form elements into a table (Drupal 6)
This file contains hidden or 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 | |
/** | |
* Theme a series of form elements into a table (Drupal 6). | |
*/ | |
function theme_D6MODULE_table_form($form) { | |
$header = array(); | |
$rows = array(); | |
foreach (element_children($form) as $i) { | |
$row = array(); | |
if (!isset($form[$i]['#sorted'])) { | |
uasort($form[$i], 'element_sort'); | |
} | |
foreach (element_children($form[$i]) as $f) { | |
$this_element = &$form[$i][$f]; | |
if (isset($this_element['#title'])) { | |
if (!isset($header[$f])) { | |
$header[$f] = $this_element['#title']; | |
} | |
unset($this_element['#title']); | |
if (isset($this_element['#label'])) { | |
$this_element['#title'] = $this_element['#label']; | |
} | |
$row[] = drupal_render($this_element); | |
} | |
} | |
$rows[] = array( | |
'data' => $row, | |
); | |
} | |
return theme('table', $header, $rows); | |
} | |
/** | |
* Implements hook_theme(). | |
*/ | |
function D6MODULE_theme() { | |
return array( | |
'D6MODULE_table_form' => array( | |
'arguments' => array('form' => NULL), | |
'file' => 'D6MODULE.admin.inc', | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment