root / drupal7 / sites / all / themes / bootstrap / theme / system / form-element-label.func.php @ 87dbc3bf
1 |
<?php
|
---|---|
2 |
/**
|
3 |
* @file
|
4 |
* form-element-label.func.php
|
5 |
*/
|
6 |
|
7 |
/**
|
8 |
* Overrides theme_form_element_label().
|
9 |
*/
|
10 |
function bootstrap_form_element_label(&$variables) { |
11 |
$element = $variables['element']; |
12 |
|
13 |
// This is also used in the installer, pre-database setup.
|
14 |
$t = get_t();
|
15 |
|
16 |
// Determine if certain things should skip for checkbox or radio elements.
|
17 |
$skip = (isset($element['#type']) && ('checkbox' === $element['#type'] || 'radio' === $element['#type'])); |
18 |
|
19 |
// If title and required marker are both empty, output no label.
|
20 |
if ((!isset($element['#title']) || $element['#title'] === '' && !$skip) && empty($element['#required'])) { |
21 |
return ''; |
22 |
} |
23 |
|
24 |
// If the element is required, a required marker is appended to the label.
|
25 |
$required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : ''; |
26 |
|
27 |
$title = filter_xss_admin($element['#title']); |
28 |
|
29 |
$attributes = array(); |
30 |
|
31 |
// Style the label as class option to display inline with the element.
|
32 |
if ($element['#title_display'] == 'after' && !$skip) { |
33 |
$attributes['class'][] = $element['#type']; |
34 |
} |
35 |
// Show label only to screen readers to avoid disruption in visual flows.
|
36 |
elseif ($element['#title_display'] == 'invisible') { |
37 |
$attributes['class'][] = 'element-invisible'; |
38 |
} |
39 |
|
40 |
if (!empty($element['#id'])) { |
41 |
$attributes['for'] = $element['#id']; |
42 |
} |
43 |
|
44 |
// Insert radio and checkboxes inside label elements.
|
45 |
$output = ''; |
46 |
if (isset($variables['#children'])) { |
47 |
$output .= $variables['#children']; |
48 |
} |
49 |
|
50 |
// Append label.
|
51 |
$output .= $t('!title !required', array('!title' => $title, '!required' => $required)); |
52 |
|
53 |
// The leading whitespace helps visually separate fields from inline labels.
|
54 |
return ' <label' . drupal_attributes($attributes) . '>' . $output . "</label>\n"; |
55 |
} |