function theme_term_level_element in Term Level Field 7
Themes the term level element into a table.
1 theme call to theme_term_level_element()
- term_level_element_info in ./
term_level_element.inc - Implements hook_element_info().
File
- ./
term_level_element.inc, line 172 - term_level_element form type
Code
function theme_term_level_element($variables) {
$element = $variables['element'];
// Theme element in a table.
$table['#theme'] = 'table';
$table['#attributes']['class'] = array(
'term-level-element-table',
);
$table['#attributes']['id'] = 'term-level-element-table-' . $element['#vid'] . '-' . $element['#parent'];
// Set table caption and header, if the element has a title.
if (!empty($element['#title'])) {
$table['#caption'] = check_plain($element['#title']);
}
if (count($element['#terms'])) {
$table['#header'][] = array(
'data' => '',
'class' => array(
'term-level-element-first-col',
),
);
}
foreach ($element['#levels'] as $level) {
if ($level === t('None')) {
// Hide label, if JS enabled (see 'Remove' link).
$level = '<span class="term-level-hide-js">' . $level . '</span>';
}
else {
$level = check_plain($level);
}
if (count($element['#terms'])) {
$table['#header'][] = array(
'data' => $level,
'class' => 'term-level-element-table-header-col',
);
}
}
// Render the listed terms.
foreach (element_children($element['terms'], TRUE) as $key) {
$row = array();
$row['class'][] = "term-level-element-table-row";
if ($element['terms'][$key]['#default_value'] == 'none') {
$row['class'][] = "term-level-hide-js";
}
$row['id'] = "term-level-element-table-row-" . $element['terms'][$key]['#tid'];
foreach (element_children($element['terms'][$key]) as $child) {
if ($child === "term-name") {
$class = "term-level-element-table-col-name";
}
else {
if ($child === "none") {
$class = "term-level-element-table-col-radio";
unset($element['terms'][$key][$child]['#title']);
// Display 'Remove' link, if JS enabled, else the 'None' radio button.
$remove_link = '<span class="term-level-show-js">' . l(t('Remove'), '', array(
'attributes' => array(
'class' => array(
'term-level-remove-links',
),
),
)) . '<span>';
$element['terms'][$key][$child]['#prefix'] = $remove_link . '<span class="term-level-hide-js">';
$element['terms'][$key][$child]['#suffix'] = '</span>';
}
else {
$class = "term-level-element-table-col-radio";
unset($element['terms'][$key][$child]['#title']);
}
}
$row['data'][] = array(
'data' => $element['terms'][$key][$child],
'class' => $class,
);
}
$table['#rows'][] = $row;
}
// Render Tag Cloud.
$tag_cloud_links = "";
if (!empty($element['tag_cloud_term_links']['#markup'])) {
$tag_cloud_links .= '<div class="term-level-element-tag-cloud-title">' . t('Additional terms:') . '</div>';
$tag_cloud_links .= '<div class="term-level-show-js">' . drupal_render($element['tag_cloud_term_links']) . '</div>';
}
else {
$tag_cloud_row['class'][] = 'term-level-hide-js';
}
$tag_cloud_options = '<div class="term-level-hide-js">' . drupal_render($element['tag_cloud_term_options']) . '</div>';
$tag_cloud_row['class'][] = 'term-level-element-tag-cloud-row';
$tag_cloud_row['data'][] = array(
'data' => $tag_cloud_links . $tag_cloud_options,
'colspan' => count($element['#levels']) + 1,
);
$table['#rows'][] = $tag_cloud_row;
return drupal_render($table);
}