You are here

public function WebhookForm::save in Webhooks 8

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

modules/webhook/src/Form/WebhookForm.php, line 16

Class

WebhookForm
Form controller for the webhook entity edit forms.

Namespace

Drupal\webhook\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $entity = $this
    ->getEntity();
  $result = $entity
    ->save();
  $link = $entity
    ->toLink($this
    ->t('View'))
    ->toRenderable();
  $message_arguments = [
    '%label' => $this->entity
      ->label(),
  ];
  $logger_arguments = $message_arguments + [
    'link' => render($link),
  ];
  if ($result == SAVED_NEW) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('New webhook %label has been created.', $message_arguments));
    $this
      ->logger('webhook')
      ->notice('Created new webhook %label', $logger_arguments);
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('The webhook %label has been updated.', $message_arguments));
    $this
      ->logger('webhook')
      ->notice('Updated new webhook %label.', $logger_arguments);
  }
  $form_state
    ->setRedirect('entity.webhook.canonical', [
    'webhook' => $entity
      ->id(),
  ]);
}