You are here

public function FieldInheritanceForm::save in Field Inheritance 8

Same name and namespace in other branches
  1. 2.0.x src/Form/FieldInheritanceForm.php \Drupal\field_inheritance\Form\FieldInheritanceForm::save()

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

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

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

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides EntityForm::save

1 call to FieldInheritanceForm::save()
FieldInheritanceAjaxForm::ajaxSubmit in src/Form/FieldInheritanceAjaxForm.php

File

src/Form/FieldInheritanceForm.php, line 478

Class

FieldInheritanceForm
Provides a form for managing field inheritance entities.

Namespace

Drupal\field_inheritance\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $field_inheritance = $this->entity;
  $field_inheritance
    ->setSourceEntityType($values['source_entity_type']);
  $field_inheritance
    ->setSourceEntityBundle($values['source_entity_bundle']);
  $field_inheritance
    ->setSourceField($values['source_field']);
  $field_inheritance
    ->setDestinationEntityType($values['destination_entity_type']);
  $field_inheritance
    ->setDestinationEntityBundle($values['destination_entity_bundle']);
  $field_inheritance
    ->setDestinationField($values['destination_field']);
  $status = $field_inheritance
    ->save();
  switch ($status) {
    case SAVED_NEW:
      $this->messenger
        ->addMessage($this
        ->t('Created the %label field inheritance.', [
        '%label' => $field_inheritance
          ->label(),
      ]));
      break;
    default:
      $this->messenger
        ->addMessage($this
        ->t('Saved the %label field inheritance.', [
        '%label' => $field_inheritance
          ->label(),
      ]));
  }
  $this->entityFieldManager
    ->clearCachedFieldDefinitions();
  $form_state
    ->setRedirectUrl($field_inheritance
    ->toUrl('collection'));
}