I was working on a project today with forms and realized, there is a prefix, a suffix, field prefix, field suffix, but no label prefix and suffix. I took the liberty of altering form.inc to accommodate this. Here is the modified code for theme_form_element()
function theme_form_element($element, $value) {
// This is also used in the installer, pre-database setup.
$t = get_t();
$output = '<div class="form-item"';
if (!empty($element['#id'])) {
$output .= ' id="'. $element['#id'] .'-wrapper"';
}
$output .= ">\n";
$required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">*</span>' : '';
if (!empty($element['#title'])) {
$title = $element['#title'];
if (!empty($element['#id'])) {
$output .= ' <label for="'. $element['#id'] .'">';
if(!empty($element['#label_prefix'])) {
$output .= $element['#label_prefix'];
}
$output .= $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required));
if(!empty($element['#label_suffix'])) {
$output .= $element['#label_suffix'];
}
$output .= "</label>\n";
}
else {
$output .= ' <label>';
if(!empty($element['#label_prefix'])) {
$output .= $element['#label_prefix'];
}
$output .= $t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required));
if(!empty($element['#label_suffix'])) {
$output .= $element['#label_suffix'];
}
$output .="</label>\n";
}
}
$output .= " $value\n";
if (!empty($element['#description'])) {
$output .= ' <div class="description">'. $element['#description'] ."</div>\n";
}
$output .= "</div>\n";
return $output;
}
and now i can add ['#label_prefix'] and ['#label_suffix'] to my form element arrays, i tested it, works perfectly.
Just wanted to throw this out there in case this hasn't been thought of before and you guys find it interesting
-Adam
Comments
Comment #1
brianV commentedFiling this properly...
Comment #2
sun.core commentedComment #3
bbu23for those who need this now, it should be done like this:
@vdsh thanks, I corrected :D
Comment #4
vdsh commentedbbu23, you had a typo, it should be
Comment #6
mickaelperrin commentedFor Drupal 8.2.x :
Comment #11
joshmillerComment #12
gnugetIs there a reason why this was closed as "won't fix"?
Comment #13
gnugetComment #14
joshmillerSorry, yes I should have explained my motivations. We have two very good examples of how to do this in contrib and zero patches for making it core. Not enough traction to keep it open when there are 18,000+ other issues that remain open. I close issues like this when I stumble on to them and it's clear people are finding this as a google search and there are good examples on how to do it without a core change.
In other words, let's keep this alive by providing a patch or telling us how important this change would be, or try to use our resources elsewhere.
Comment #24
quietone commented@joshmiller, thank you for taking care of the issue queue!
The proposal doesn't met the Criteria for evaluating proposed changes. In this case, there is not demonstrated demand and support for the change. Plus, @joshmiller says there are contrib solutions.
Comment #26
quietone commentedThis should be won't fix, https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...