protected function QuickEditFieldForm::simplify in Drupal 8
Same name and namespace in other branches
- 9 core/modules/quickedit/src/Form/QuickEditFieldForm.php \Drupal\quickedit\Form\QuickEditFieldForm::simplify()
- 10 core/modules/quickedit/src/Form/QuickEditFieldForm.php \Drupal\quickedit\Form\QuickEditFieldForm::simplify()
Simplifies the field edit form for in-place editing.
This function:
- Hides the field label inside the form, because JavaScript displays it outside the form.
- Adjusts textarea elements to fit their content.
Parameters
array &$form: A reference to an associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
1 call to QuickEditFieldForm::simplify()
- QuickEditFieldForm::buildForm in core/
modules/ quickedit/ src/ Form/ QuickEditFieldForm.php - Builds a form for a single entity field.
File
- core/
modules/ quickedit/ src/ Form/ QuickEditFieldForm.php, line 199
Class
- QuickEditFieldForm
- Builds and process a form for editing a single entity field.
Namespace
Drupal\quickedit\FormCode
protected function simplify(array &$form, FormStateInterface $form_state) {
$field_name = $form_state
->get('field_name');
$widget_element =& $form[$field_name]['widget'];
// Hide the field label from displaying within the form, because JavaScript
// displays the equivalent label that was provided within an HTML data
// attribute of the field's display element outside of the form. Do this for
// widgets without child elements (like Option widgets) as well as for ones
// with per-delta elements. Skip single checkboxes, because their title is
// key to their UI. Also skip widgets with multiple subelements, because in
// that case, per-element labeling is informative.
$num_children = count(Element::children($widget_element));
if ($num_children == 0 && $widget_element['#type'] != 'checkbox') {
$widget_element['#title_display'] = 'invisible';
}
if ($num_children == 1 && isset($widget_element[0]['value'])) {
// @todo While most widgets name their primary element 'value', not all
// do, so generalize this.
$widget_element[0]['value']['#title_display'] = 'invisible';
}
// Adjust textarea elements to fit their content.
if (isset($widget_element[0]['value']['#type']) && $widget_element[0]['value']['#type'] == 'textarea') {
$lines = count(explode("\n", $widget_element[0]['value']['#default_value']));
$widget_element[0]['value']['#rows'] = $lines + 1;
}
}