You are here

public function ActionEditFieldForm::buildForm in Paragraphs table 8

Builds a form for a single entity field.

Overrides FormInterface::buildForm

File

src/Form/ActionEditFieldForm.php, line 72

Class

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

Namespace

Drupal\paragraphs_table\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity = NULL, $field_name = NULL) {
  if (!$form_state
    ->has('entity')) {
    $this
      ->init($form_state, $entity, $field_name);
  }

  // Add the field form.
  $form_state
    ->get('form_display')
    ->buildForm($entity, $form, $form_state);

  // Add a dummy changed timestamp field to attach form errors to.
  if ($entity instanceof EntityChangedInterface) {
    $form['changed_field'] = [
      '#type' => 'hidden',
      '#value' => $entity
        ->getChangedTime(),
    ];
  }
  $form[$field_name]["widget"]["add_more"]["#access"] = FALSE;
  $form[$field_name]['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Save'),
  ];

  // Use the non-inline form error display for Quick Edit forms, because in
  // this case the errors are already near the form element.
  $form['#disable_inline_form_errors'] = TRUE;

  // Simplify it for optimal in-place use.
  $this
    ->simplify($form, $form_state);
  return $form;
}