You are here

public function IdpForm::save in SAML Service Provider 3.x

Same name and namespace in other branches
  1. 8.3 src/Form/IdpForm.php \Drupal\saml_sp\Form\IdpForm::save()
  2. 8.2 src/Form/IdpForm.php \Drupal\saml_sp\Form\IdpForm::save()
  3. 4.x src/Form/IdpForm.php \Drupal\saml_sp\Form\IdpForm::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/IdpForm.php, line 285

Class

IdpForm
Provides the form to configure the IdP.

Namespace

Drupal\saml_sp\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $idp = $this->entity;
  $values = $form_state
    ->getValues();
  if (!is_array($values['idp']['x509_cert'])) {
    $values['idp']['x509_cert'] = [
      $values['idp']['x509_cert'],
    ];
  }
  foreach ($values['idp'] as $key => $value) {
    $idp
      ->set($key, $value);
  }
  $status = $idp
    ->save();
  if ($status) {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Saved the %label Identity Provider.', [
      '%label' => $idp
        ->label(),
    ]));
  }
  else {
    \Drupal::messenger()
      ->addMessage($this
      ->t('The %label Identity Provider was not saved.', [
      '%label' => $idp
        ->label(),
    ]));
  }
  $form_state
    ->setRedirect('entity.idp.collection');
}