You are here

public function ApiKeyForm::save in Services API Key Authentication 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/ApiKeyForm.php \Drupal\services_api_key_auth\Form\ApiKeyForm::save()
  2. 8 src/Form/ApiKeyForm.php \Drupal\services_api_key_auth\Form\ApiKeyForm::save()
  3. 2.0.x src/Form/ApiKeyForm.php \Drupal\services_api_key_auth\Form\ApiKeyForm::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/ApiKeyForm.php, line 93

Class

ApiKeyForm
Class ApiKeyForm.

Namespace

Drupal\services_api_key_auth\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $api_key = $this->entity;
  $uid = $api_key->user_uuid;
  $api_key->user_uuid = self::getUuid($uid);
  $status = $api_key
    ->save();
  switch ($status) {
    case SAVED_NEW:
      $this
        ->messenger()
        ->addStatus($this
        ->t('Created the %label API Key.', [
        '%label' => $api_key
          ->label(),
      ]));
      break;
    default:
      $this
        ->messenger()
        ->addStatus($this
        ->t('Saved the %label API Key.', [
        '%label' => $api_key
          ->label(),
      ]));
  }
  $form_state
    ->setRedirectUrl($api_key
    ->toUrl('collection'));
}