You are here

public function ContentHubSettingsForm::validateWebhook in Acquia Content Hub 8.2

Validates webhook update.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Throws

\Exception

File

src/Form/ContentHubSettingsForm.php, line 361

Class

ContentHubSettingsForm
Defines the form to configure the Content Hub connection settings.

Namespace

Drupal\acquia_contenthub\Form

Code

public function validateWebhook(array &$form, FormStateInterface $form_state) : void {
  if (!empty($form_state
    ->getErrors())) {
    return;
  }
  $webhook_url = $this
    ->getFormattedWebhookUrl($form_state);
  if (!UrlHelper::isValid($webhook_url, TRUE)) {
    $form_state
      ->setErrorByName('webhook', $this
      ->t('Please type a publicly accessible url.'));
  }
  if ($this->chConnectionManager
    ->webhookIsRegistered($webhook_url)) {
    $form_state
      ->setErrorByName('webhook', $this
      ->t('This webhook is already being used. (%name) Please insert another one, or unregister the existing one first.', [
      '%name' => $webhook_url,
    ]));
  }
}