You are here

protected function ActionEditFieldForm::simplify in Paragraphs table 8

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 ActionEditFieldForm::simplify()
ActionEditFieldForm::buildForm in src/Form/ActionEditFieldForm.php
Builds a form for a single entity field.

File

src/Form/ActionEditFieldForm.php, line 180

Class

ActionEditFieldForm
Builds and process a form for editing a single entity field.

Namespace

Drupal\paragraphs_table\Form

Code

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;
  }
}