You are here

public function WebhookConfigForm::validateForm in Webhooks 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormBase::validateForm

File

src/Form/WebhookConfigForm.php, line 267

Class

WebhookConfigForm
Class Webhook Config Form.

Namespace

Drupal\webhooks\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('type') == 'incoming') {

    // payload_url is required but not used on incoming webhooks.
    // Skipping the value entirely could break data model assumptions.
    $form_state
      ->setValue('payload_url', 'http://example.com/webhook');
  }
  elseif ($form_state
    ->isValueEmpty('payload_url')) {
    $form_state
      ->setErrorByName('payload_url', $this
      ->t('Outgoing webhooks require a Payload URL'));
  }
  if ($form_state
    ->getValue('type') == 'outgoing' && $this
    ->isEmptyList($form_state
    ->getValue('events'))) {
    $form_state
      ->setErrorByName('events', $this
      ->t('Outgoing webhooks require one or more events to operate.'));
  }
  parent::validateForm($form, $form_state);
}