function theme_date_form_element in Date 7.3
Same name and namespace in other branches
- 7.2 date.theme \theme_date_form_element()
Render a date combo as a form element.
File
- ./
date.theme, line 468 - Theme functions.
Code
function theme_date_form_element($variables) {
$element =& $variables['element'];
// Detect whether element is multiline.
$count = preg_match_all('`<(?:div|span)\\b[^>]* class="[^"]*\\b(?:date-no-float|date-clear)\\b`', $element['#children'], $matches, PREG_OFFSET_CAPTURE);
$multiline = FALSE;
if ($count > 1) {
$multiline = TRUE;
}
elseif ($count) {
$before = substr($element['#children'], 0, $matches[0][0][1]);
if (preg_match('`<(?:div|span)\\b[^>]* class="[^"]*\\bdate-float\\b`', $before)) {
$multiline = TRUE;
}
}
// Detect if there is more than one subfield.
$count = count(explode('<label', $element['#children'])) - 1;
if ($count == 1) {
// If there is only one subfield, hide the label of the main field only if
// the label of the subfield is visible.
if (empty($variables['element']['value']['#instance']) || empty($variables['element']['value']['#instance']['widget']) || empty($variables['element']['value']['#instance']['widget']['settings']) || empty($variables['element']['value']['#instance']['widget']['settings']['label_position']) || $variables['element']['value']['#instance']['widget']['settings']['label_position'] != 'none') {
$element['#title_display'] = 'none';
}
}
// Wrap children with a div and add an extra class if element is multiline.
$element['#children'] = '<div class="date-form-element-content' . ($multiline ? ' date-form-element-content-multiline' : '') . '">' . $element['#children'] . '</div>';
return theme('form_element', $variables);
}