function theme_gathercontent_tableselect in GatherContent 7.3
Returns HTML for a table with radio buttons or checkboxes.
See Drupal core's theme_tableselect() as reference.
Parameters
array $variables: An associative array containing:
- element: An associative array containing the properties and children of the tableselect element. Properties used: #header, #options, #empty, and #js_select. The #options property is an array of selection options; each array element of #options is an array of properties. These properties can include #attributes, which is added to the table row's HTML attributes; see theme_table().
Return value
string The rendered markup.
2 theme calls to theme_gathercontent_tableselect()
- gathercontent_element_info in ./
gathercontent.theme.inc - Implements hook_element_info().
- gathercontent_import_form_content_select in ./
gathercontent.import.inc - Content select import form.
File
- ./
gathercontent.theme.inc, line 157 - Form elements and theme functions for GatherContent module.
Code
function theme_gathercontent_tableselect(array $variables) {
$output = '';
$element = $variables['element'];
$gathercontent_module_path = drupal_get_path('module', 'gathercontent');
// Libraries module and tablesorter plugin are optional.
// If tablesorter available, add it to the scope.
if (module_exists('libraries')) {
$library = libraries_detect('tablesorter-mottie');
if ($library['installed'] && isset($element['#tablesorter'])) {
$element['#attributes']['class'][] = 'tablesorter-enabled';
drupal_add_js($gathercontent_module_path . '/js/gathercontent-tablesorter.js');
libraries_load('tablesorter-mottie');
}
}
$table = array(
'header' => $element['#header'],
'rows' => [],
'empty' => $element['#empty'],
'attributes' => $element['#attributes'],
);
// Generate a table row for each selectable item in #options.
foreach (element_children($element) as $key) {
$row = array();
foreach ($element['#header'] as $column => $column_title) {
$row[$column] = array(
'data' => drupal_render($element[$key][$column]),
);
if (isset($element[$key][$column]['#attributes'])) {
$row[$column] += $element[$key][$column]['#attributes'];
}
}
$table['rows'][$key] = $row;
}
// Add an empty header or a "Select all" checkbox to provide room for the
// checkboxes/radios in the first table column.
if (isset($element['#js_select'])) {
// Add a "Select all" checkbox.
drupal_add_js($gathercontent_module_path . '/js/gathercontent-tableselect.js');
array_unshift($element['#header'], array(
'class' => array(
'select-all',
),
'data-sorter' => 'false',
));
}
else {
// Add an empty header when radio buttons are displayed or a "Select all"
// checkbox is not desired.
array_unshift($element['#header'], '');
}
if (!empty($element['#filterwrapper']) && is_array($element['#filterwrapper'])) {
$filterwrapper = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'gathercontent-table--header',
),
),
);
foreach ($element['#filterwrapper'] as $key => $classes) {
$filterwrapper[$key] = array(
'#type' => 'container',
'#attributes' => array(
'class' => is_array($classes) ? $classes : array(
$classes,
),
),
);
}
$output .= drupal_render($filterwrapper);
}
if (!empty($element['#filterdescription'])) {
$filterdescription = array(
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => $element['#filterdescription'],
'#attributes' => array(
'class' => array(
'description',
),
),
);
$output .= drupal_render($filterdescription);
}
$output .= theme('table', $table);
return $output;
}