You are here

public function SignupForm::submitForm in SendinBlue 8

Same name and namespace in other branches
  1. 8.2 src/Form/SignupForm.php \Drupal\sendinblue\Form\SignupForm::submitForm()

Form submission handler.

Parameters

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

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

Overrides ContentEntityForm::submitForm

File

src/Form/SignupForm.php, line 417

Class

SignupForm
Form controller for the content_entity_example entity edit forms.

Namespace

Drupal\sendinblue\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if (!$form_state
    ->getValue([
    'mode',
    SendinblueManager::SENDINBLUE_SIGNUP_PAGE,
  ])) {
    $form_state
      ->setValue([
      'path',
    ], '');
  }
  $signup_mode = array_sum($form_state
    ->getValue([
    'mode',
  ]));
  $signup_path = $form_state
    ->getValue([
    'path',
  ]);
  $form_state
    ->setValue([
    'mode',
  ], $signup_mode);
  $this->entity->title = $form_state
    ->getValue([
    'title',
  ]);
  $this->entity->name = $form_state
    ->getValue([
    'name',
  ]);
  $this->entity->mode = $signup_mode;
  $this->entity->settings = [
    'description' => $form_state
      ->getValue([
      'description',
    ]),
    'path' => $signup_path,
    'fields' => $form_state
      ->getValue([
      'fields',
    ]),
    'subscription' => $form_state
      ->getValue([
      'subscription',
    ]),
  ];
  $this->messenger
    ->addStatus($this
    ->t('Signup form @name has been saved.', [
    '@name' => $form_state
      ->getValue([
      'title',
    ]),
  ]));
  if (isset($signup_path)) {

    // We have a new (or removed) path. Rebuild menus.
    $this->routeBuilder
      ->rebuild();
  }
  $form_state
    ->setRedirect('admin/config/system/sendinblue/signup');
  parent::submitForm($form, $form_state);
}