You are here

public function EckEntityTypeFormBase::save in Entity Construction Kit (ECK) 8

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

File

src/Form/EntityType/EckEntityTypeFormBase.php, line 148

Class

EckEntityTypeFormBase
Class EckEntityTypeFormBase.

Namespace

Drupal\eck\Form\EntityType

Code

public function save(array $form, FormStateInterface $form_state) {

  // The entity object is already populated with the values from the form.
  $status = $this->entity
    ->save();
  $messageArgs = [
    '%label' => $this->entity
      ->label(),
  ];
  $message = $this
    ->t('Entity type %label has been added.', $messageArgs);
  if ($status === SAVED_UPDATED) {
    $message = $this
      ->t('Entity type %label has been updated.', $messageArgs);
  }
  \Drupal::messenger()
    ->addMessage($message);

  // Redirect the user back to the listing route after the save operation.
  $form_state
    ->setRedirect('eck.entity_type.list');
}