You are here

public function TemplateForm::save in Workbench Email 8

Same name and namespace in other branches
  1. 2.x src/Form/TemplateForm.php \Drupal\workbench_email\Form\TemplateForm::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/TemplateForm.php, line 269

Class

TemplateForm
Class TemplateForm.

Namespace

Drupal\workbench_email\Form

Code

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

  /** @var \Drupal\workbench_email\TemplateInterface $workbench_email_template */
  $workbench_email_template = $this->entity;
  $recipient_types = $workbench_email_template
    ->recipientTypes();

  /** @var \Drupal\workbench_email\Plugin\RecipientTypeInterface $plugin */
  foreach ($recipient_types as $plugin_id => $plugin) {
    if ($plugin
      ->hasFormClass('configure')) {
      $subform_state = SubformState::createForSubform($form['recipient_types']['settings'][$plugin_id], $form, $form_state);
      $plugin
        ->submitConfigurationForm($form['recipient_types']['settings'][$plugin_id], $subform_state);
    }
  }
  $status = $workbench_email_template
    ->save();
  switch ($status) {
    case SAVED_NEW:
      $this->messenger
        ->addStatus($this
        ->t('Created the %label Email Template.', [
        '%label' => $workbench_email_template
          ->label(),
      ]));
      break;
    default:
      $this->messenger
        ->addStatus($this
        ->t('Saved the %label Email Template.', [
        '%label' => $workbench_email_template
          ->label(),
      ]));
  }
  $form_state
    ->setRedirectUrl($workbench_email_template
    ->toUrl('collection'));
}