You are here

public function FieldConfigDeleteForm::submitForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field_ui/src/Form/FieldConfigDeleteForm.php \Drupal\field_ui\Form\FieldConfigDeleteForm::submitForm()
  2. 9 core/modules/field_ui/src/Form/FieldConfigDeleteForm.php \Drupal\field_ui\Form\FieldConfigDeleteForm::submitForm()

Overrides EntityDeleteFormTrait::submitForm

File

core/modules/field_ui/src/Form/FieldConfigDeleteForm.php, line 94

Class

FieldConfigDeleteForm
Provides a form for removing a field from a bundle.

Namespace

Drupal\field_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $field_storage = $this->entity
    ->getFieldStorageDefinition();
  $bundles = $this->entityTypeBundleInfo
    ->getBundleInfo($this->entity
    ->getTargetEntityTypeId());
  $bundle_label = $bundles[$this->entity
    ->getTargetBundle()]['label'];
  if ($field_storage && !$field_storage
    ->isLocked()) {
    $this->entity
      ->delete();
    $this
      ->messenger()
      ->addStatus($this
      ->t('The field %field has been deleted from the %type content type.', [
      '%field' => $this->entity
        ->label(),
      '%type' => $bundle_label,
    ]));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('There was a problem removing the %field from the %type content type.', [
      '%field' => $this->entity
        ->label(),
      '%type' => $bundle_label,
    ]));
  }
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());

  // Fields are purged on cron. However field module prevents disabling modules
  // when field types they provided are used in a field until it is fully
  // purged. In the case that a field has minimal or no content, a single call
  // to field_purge_batch() will remove it from the system. Call this with a
  // low batch limit to avoid administrators having to wait for cron runs when
  // removing fields that meet this criteria.
  field_purge_batch(10);
}