You are here

public function EasyEmailTypeForm::save in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EasyEmailTypeForm.php \Drupal\easy_email\Form\EasyEmailTypeForm::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

File

src/Form/EasyEmailTypeForm.php, line 297

Class

EasyEmailTypeForm
Class EasyEmailTypeForm.

Namespace

Drupal\easy_email\Form

Code

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

  /** @var \Drupal\easy_email\Entity\EasyEmailTypeInterface $easy_email_type */
  $easy_email_type = $this->entity;
  if ($easy_email_type
    ->isNew()) {
    $easy_email_type
      ->save();
    $form_state
      ->setRedirect('entity.easy_email_type.edit_form', [
      'easy_email_type' => $easy_email_type
        ->id(),
    ]);
    $this->messenger
      ->addMessage($this
      ->t('Created the %label Email type. You may now edit the template below.', [
      '%label' => $easy_email_type
        ->label(),
    ]));
  }
  else {
    $easy_email_type
      ->setRecipient($this
      ->explodeAndTrim($form_state
      ->getValue('recipient')))
      ->setCc($this
      ->explodeAndTrim($form_state
      ->getValue('cc')))
      ->setBcc($this
      ->explodeAndTrim($form_state
      ->getValue('bcc')))
      ->setAttachment($this
      ->explodeAndTrim($form_state
      ->getValue('attachment')))
      ->save();
    $this->messenger
      ->addMessage($this
      ->t('Saved the %label Email type.', [
      '%label' => $easy_email_type
        ->label(),
    ]));
    $form_state
      ->setRedirectUrl($easy_email_type
      ->toUrl('collection'));
  }
}