function FieldConfigEditForm::save

Same name and namespace in other branches
  1. 9 core/modules/field_ui/src/Form/FieldConfigEditForm.php \Drupal\field_ui\Form\FieldConfigEditForm::save()
  2. 8.9.x core/modules/field_ui/src/Form/FieldConfigEditForm.php \Drupal\field_ui\Form\FieldConfigEditForm::save()
  3. 10 core/modules/field_ui/src/Form/FieldConfigEditForm.php \Drupal\field_ui\Form\FieldConfigEditForm::save()

Overrides EntityForm::save

File

core/modules/field_ui/src/Form/FieldConfigEditForm.php, line 381

Class

FieldConfigEditForm
Provides a form for the field settings form.

Namespace

Drupal\field_ui\Form

Code

public function save(array $form, FormStateInterface $form_state) {
    // Save field config.
    try {
        try {
            $this->entity
                ->save();
        } catch (EntityStorageException $exception) {
            $this->handleEntityStorageException($form_state, $exception);
            return;
        }
        if (isset($form_state->getStorage()['default_options'])) {
            $default_options = $form_state->getStorage()['default_options'];
            // Configure the default display modes.
            $this->entityTypeId = $this->entity
                ->getTargetEntityTypeId();
            $this->bundle = $this->entity
                ->getTargetBundle();
            $this->configureEntityFormDisplay($this->entity
                ->getName(), $default_options['entity_form_display'] ?? []);
            $this->configureEntityViewDisplay($this->entity
                ->getName(), $default_options['entity_view_display'] ?? []);
        }
        if ($this->entity
            ->isNew()) {
            // Delete the temp store entry.
            $this->tempStore
                ->delete($this->entity
                ->getTargetEntityTypeId() . ':' . $this->entity
                ->getName());
        }
        $this->messenger()
            ->addStatus($this->t('Saved %label configuration.', [
            '%label' => $this->entity
                ->getLabel(),
        ]));
        $request = $this->getRequest();
        if (($destinations = $request->query
            ->all('destinations')) && ($next_destination = FieldUI::getNextDestination($destinations))) {
            $request->query
                ->remove('destinations');
            $form_state->setRedirectUrl($next_destination);
        }
        else {
            $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->entity
                ->getTargetEntityTypeId(), $this->entity
                ->getTargetBundle()));
        }
    } catch (\Exception $e) {
        $this->messenger()
            ->addError($this->t('Attempt to update field %label failed: %message.', [
            '%label' => $this->entity
                ->getLabel(),
            '%message' => $e->getMessage(),
        ]));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.