You are here

public function OpenIDConnectClientFormBase::save in OpenID Connect / OAuth client 2.x

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/OpenIDConnectClientFormBase.php, line 180

Class

OpenIDConnectClientFormBase
Form handler for the OpenID Connect client add and edit forms.

Namespace

Drupal\openid_connect\Form

Code

public function save(array $form, FormStateInterface $form_state) : int {
  $status = parent::save($form, $form_state);

  /** @var \Drupal\openid_connect\OpenIDConnectClientEntityInterface $entity */
  $entity = $this->entity;

  // Create an edit link.
  $edit_link = Link::fromTextAndUrl($this
    ->t('Edit'), $entity
    ->toUrl())
    ->toString();
  if ($status === SAVED_UPDATED) {

    // If we edited an existing entity...
    $this
      ->messenger()
      ->addMessage($this
      ->t('OpenID Connect client %label has been updated.', [
      '%label' => $entity
        ->label(),
    ]));
    $this
      ->logger('openid_connect')
      ->notice('OpenID Connect client %label has been updated.', [
      '%label' => $entity
        ->label(),
      'alink' => $edit_link,
    ]);
  }
  else {

    // If we created a new entity...
    $this
      ->messenger()
      ->addMessage($this
      ->t('OpenID Connect client %label has been added.', [
      '%label' => $entity
        ->label(),
    ]));
    $this
      ->logger('openid_connect')
      ->notice('OpenID Connect client %label has been added.', [
      '%label' => $entity
        ->label(),
      'alink' => $edit_link,
    ]);
  }
  $form_state
    ->setRedirect('entity.openid_connect_client.list');
  return $status;
}