You are here

public function ConditionalFieldDeleteForm::submitForm in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/Form/ConditionalFieldDeleteForm.php \Drupal\conditional_fields\Form\ConditionalFieldDeleteForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

1 call to ConditionalFieldDeleteForm::submitForm()
ConditionalFieldDeleteFormTab::submitForm in src/Form/ConditionalFieldDeleteFormTab.php
Form submission handler.
1 method overrides ConditionalFieldDeleteForm::submitForm()
ConditionalFieldDeleteFormTab::submitForm in src/Form/ConditionalFieldDeleteFormTab.php
Form submission handler.

File

src/Form/ConditionalFieldDeleteForm.php, line 73

Class

ConditionalFieldDeleteForm
A form to delete a conditional field.

Namespace

Drupal\conditional_fields\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (empty($this->entityType) || empty($this->bundle) || empty($this->fieldName) || empty($this->uuid)) {
    return;
  }

  /** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $entity */
  $entity = \Drupal::entityTypeManager()
    ->getStorage('entity_form_display')
    ->load($this->entityType . '.' . $this->bundle . '.default');
  if (!$entity) {
    return;
  }
  $field = $entity
    ->getComponent($this->fieldName);
  unset($field['third_party_settings']['conditional_fields'][$this->uuid]);
  $entity
    ->setComponent($this->fieldName, $field);
  $entity
    ->save();
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
}