You are here

public function WebhookForm::buildForm in Fastly 8.3

Form constructor.

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

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/WebhookForm.php, line 71

Class

WebhookForm
Class WebhookForm.

Namespace

Drupal\fastly\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('fastly.settings');
  $form['webhook']['webhook_enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Webhooks'),
    '#description' => $this
      ->t("Enables or disables webhook"),
    '#default_value' => $config
      ->get('webhook_enabled'),
  ];
  $form['webhook']['webhook_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Webhook URL'),
    '#default_value' => $config
      ->get('webhook_url'),
    '#required' => FALSE,
    '#description' => $this
      ->t("Incoming WebHook URL"),
    '#states' => [
      'visible' => [
        ':input[name="webhook_enabled"]' => [
          'checked' => TRUE,
        ],
      ],
      'required' => [
        ':input[name="webhook_enabled"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['webhook']['webhook_notifications'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Send notifications for this events'),
    '#description' => $this
      ->t('Choose which notifications to push to your webhook'),
    '#options' => [
      'purge_keys' => $this
        ->t('Purge by keys'),
      'purge_all' => $this
        ->t('Purge all'),
      'vcl_update' => $this
        ->t('VCL update'),
      'config_save' => $this
        ->t('Config save'),
      'maintenance_page' => $this
        ->t('Maintenance page upload'),
    ],
    '#default_value' => $config
      ->get('webhook_notifications'),
    '#multiple' => TRUE,
    '#size' => 5,
  ];
  return parent::buildForm($form, $form_state);
}