'form_required_marker', '#element' => $element);
if ($title && $required = !empty($element['#required']) ? drupal_render($marker) : '') {
$title .= ' ' . $required;
}
$display = isset($element['#title_display']) ? $element['#title_display'] : 'before';
$type = !empty($element['#type']) ? $element['#type'] : FALSE;
$checkbox = $type && $type === 'checkbox';
$radio = $type && $type === 'radio';
// Immediately return if the element is not a checkbox or radio and there is
// no label to be rendered.
if (!$checkbox && !$radio && ($display === 'none' || !$title)) {
return '';
}
// Retrieve the label attributes array.
$attributes = &_bootstrap_get_attributes($element, 'label_attributes');
// Add Bootstrap label class.
$attributes['class'][] = 'control-label';
// Add the necessary 'for' attribute if the element ID exists.
if (!empty($element['#id'])) {
$attributes['for'] = $element['#id'];
}
// Checkboxes and radios must construct the label differently.
if ($checkbox || $radio) {
if ($display === 'before') {
$output .= $title;
}
elseif ($display === 'none' || $display === 'invisible') {
$output .= '' . $title . '';
}
// Inject the rendered checkbox or radio element inside the label.
if (!empty($element['#children'])) {
$output .= $element['#children'];
}
if ($display === 'after') {
$output .= $title;
}
}
// Otherwise, just render the title as the label.
else {
// Show label only to screen readers to avoid disruption in visual flows.
if ($display === 'invisible') {
$attributes['class'][] = 'element-invisible';
}
$output .= $title;
}
// The leading whitespace helps visually separate fields from inline labels.
return ' \n";
}