FieldConfigDeleteForm::submitForm

public FieldConfigDeleteForm::submitForm(array &$form, FormStateInterface $form_state)

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

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 EntityDeleteFormTrait::submitForm

File

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

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->entityManager->getBundleInfo($this->entity->getTargetEntityTypeId());
  $bundle_label = $bundles[$this->entity->getTargetBundle()]['label'];

  if ($field_storage && !$field_storage->isLocked()) {
    $this->entity->delete();
    drupal_set_message($this->t('The field %field has been deleted from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)));
  }
  else {
    drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)), 'error');
  }

  $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);
}
doc_Drupal
2016-10-29 09:11:01
Comments
Leave a Comment

Please login to continue.