You are here

public function IdpForm::save in SAML Service Provider 8.2

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

Class

IdpForm

Namespace

Drupal\saml_sp\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $idp = $this->entity;
  $values = $form_state
    ->getValues();
  foreach ($values['idp'] as $key => $value) {
    $method = 'set' . ucfirst($key);
    $idp
      ->{$method}($value);
  }
  $status = $idp
    ->save();
  if ($status) {
    drupal_set_message($this
      ->t('Saved the %label Identity Provider.', array(
      '%label' => $idp
        ->label(),
    )));
  }
  else {
    drupal_set_message($this
      ->t('The %label Identity Provider was not saved.', array(
      '%label' => $example
        ->label(),
    )));
  }
  $form_state
    ->setRedirect('entity.idp.collection');
}