Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By penyaskito on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
Issue links:
Description:
For short form fields it makes sense to have the #description
appear below the form widget; however, in long lists of checkboxes and/or radio buttons it would be nice to be able to have a toggle whether the #description
appears above, or below, the form widget.
The is a new "#description_display
" option with three allowed values, consistent with '#title_display
': "before
", "after
" and "invisible
".
There is no UI in core for toggling this behavior for existing forms.
Example:
public function buildForm(array $form, FormStateInterface $form_state) {
$form['form_textfield_test_description_before'] = array(
'#type' => 'textfield',
'#title' => 'Textfield test for description before element',
'#description' => 'Textfield test for description before element',
'#description_display' => 'before',
);
$form['form_textfield_test_description_after'] = array(
'#type' => 'textfield',
'#title' => 'Textfield test for description after element',
'#description' => 'Textfield test for description after element',
'#description_display' => 'after',
);
$form['form_textfield_test_description_invisible'] = array(
'#type' => 'textfield',
'#title' => 'Textfield test for visually-hidden description',
'#description' => 'Textfield test for visually-hidden description',
'#description_display' => 'invisible',
);
return $form;
}
Impacts:
Module developers
Themers