You are here

public function MailchimpListsWebhookSettingsForm::buildForm in Mailchimp 8

Same name and namespace in other branches
  1. 2.x modules/mailchimp_lists/src/Form/MailchimpListsWebhookSettingsForm.php \Drupal\mailchimp_lists\Form\MailchimpListsWebhookSettingsForm::buildForm()

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

modules/mailchimp_lists/src/Form/MailchimpListsWebhookSettingsForm.php, line 64

Class

MailchimpListsWebhookSettingsForm
Configure settings for a Mailchimp list webhook.

Namespace

Drupal\mailchimp_lists\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $list_id = $this
    ->getRequest()->attributes
    ->get('_raw_variables')
    ->get('list_id');
  $list = mailchimp_get_list($list_id);
  $form_state
    ->set('list', $list);
  $default_webhook_events = mailchimp_lists_default_webhook_events();
  $enabled_webhook_events = mailchimp_lists_enabled_webhook_events($list_id);
  $form['webhook_events'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Enabled webhook events for the @name audience', [
      '@name' => $list->name,
    ]),
    '#tree' => TRUE,
  ];
  foreach ($default_webhook_events as $event => $name) {
    $form['webhook_events'][$event] = [
      '#type' => 'checkbox',
      '#title' => $name,
      '#default_value' => in_array($event, $enabled_webhook_events),
    ];
  }
  return parent::buildForm($form, $form_state);
}