Active
Project:
Form Table
Version:
5.x-1.0
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
19 Feb 2014 at 12:28 UTC
Updated:
19 Feb 2014 at 12:28 UTC
The module was ported to Drupal 7.
File: formtable.module
<?php
/**
* @file
* Defines 'formtable' and 'formrow' Form API elements.
*/
/**
* Implementation of hook_element_info().
*/
function formtable_element_info() {
$types = array();
$types['formtable'] = array(
'#input' => TRUE,
'#theme' => array('formtable'),
);
$types['formrow'] = array(
'#input' => TRUE,
'#theme' => array('formrow'),
);
return $types;
}
/**
* Implementation of hook_theme().
*/
function formtable_theme($existing, $type, $theme, $path) {
return array(
'formtable' => array(
'render element' => 'element',
),
'formrow' => array(
'render element' => 'element',
),
);
}
/**
* Format a formtable element.
*/
function theme_formtable($element) {
//Load the module CSS
drupal_add_css(drupal_get_path('module', 'formtable') . '/formtable.css');
$reset_element = reset($element);
if (!empty($reset_element)) {
$element = $reset_element;
}
if (empty($element['#type'])) {
return $output = '';
}
$children = element_children($element, TRUE);
if ($element['#children'] == '') {
foreach ($children as $key) {
$element['#children'] .= drupal_render($element[$key]);
}
}
$output = "<div class=\"form-table\">\n";
if ($element['#title']) {
$output .= "<span class=\"table-title\">" . $element['#title'] . ':</span>';
}
if ($element['#description']) {
$output .= "\n<div class=\"description\">" . $element['#description'] . "</div>\n";
}
$output .= "\n<table id=\"" . $element['#id'] . '"' . drupal_attributes($element['#attributes']) . ">\n";
if (!empty($element['#caption']) && $element['#caption']) {
$output .= "\t<caption>" . $element['#caption'] . "</caption>\n";
}
if ($element['#header']) {
$output .= "\t<thead>\n\t\t<tr>\n";
foreach ($element['#header'] as $col_header) {
$output .= "\t\t\t<th>" . $col_header . "</th>\n";
}
$output .= "\t\t</tr>\n\t</thead>\n";
}
$output .= "\t<tbody>\n";
$output .= $element['#children'];
$output .= "\t</tbody>\n";
$output .= "</table>\n</div>\n";
return $output;
}
/**
* Format a formrow element.
*/
function theme_formrow($element) {
$reset_element = reset($element);
if (!empty($reset_element)) {
$element = $reset_element;
}
if (empty($element['#type'])) {
return $output = '';
}
$children = element_children($element, TRUE);
if ($element['#children'] == '') {
foreach ($children as $key) {
$element['#children'] .= drupal_render($element[$key]);
}
}
$output = "\t<tr id=\"" . $element['#id'] . "\"" . drupal_attributes($element['#attributes']) . '>' . $element['#children'] . "</tr>\n";
return $output;
}