protected QuickEditFieldForm::simplify(array &$form, FormStateInterface $form_state)
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.
File
- core/modules/quickedit/src/Form/QuickEditFieldForm.php, line 205
Class
- QuickEditFieldForm
- Builds and process a form for editing a single entity field.
Namespace
Drupal\quickedit\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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; } } |
Please login to continue.