You are here

protected function MailchimpListsSelectWidget::subscribeCheckboxShown in Mailchimp 2.x

Parameters

\Drupal\Core\Form\FormStateInterface $form_state:

$hide_subscribe_checkbox:

$at_least_one_interest_group:

$email:

$mailchimp_list_id:

Return value

bool

2 calls to MailchimpListsSelectWidget::subscribeCheckboxShown()
MailchimpListsSelectWidget::setupSubscribeCheckbox in modules/mailchimp_lists/src/Plugin/Field/FieldWidget/MailchimpListsSelectWidget.php
MailchimpListsSelectWidget::setupUnsubscribeCheckbox in modules/mailchimp_lists/src/Plugin/Field/FieldWidget/MailchimpListsSelectWidget.php

File

modules/mailchimp_lists/src/Plugin/Field/FieldWidget/MailchimpListsSelectWidget.php, line 291

Class

MailchimpListsSelectWidget
Plugin implementation of the 'mailchimp_lists_select' widget.

Namespace

Drupal\mailchimp_lists\Plugin\Field\FieldWidget

Code

protected function subscribeCheckboxShown(FormStateInterface $form_state, $hide_subscribe_checkbox, $at_least_one_interest_group, $email, $mailchimp_list_id) : bool {

  // TRUE if interest groups are enabled for this list.
  $show_interest_groups = $this->fieldDefinition
    ->getSetting('show_interest_groups');

  // TRUE if widget is being used to set default values via admin form.
  $is_default_value_widget = $this
    ->isDefaultValueWidget($form_state);

  // Hide the Subscribe checkbox if:
  // - The form is not being used to configure default values.
  // - The field is configured to show interest groups.
  // - The field is configured to hide the Subscribe checkbox.
  // - The list has at least one interest group.
  // This allows users to skip the redundant step of checking the Subscribe
  // checkbox when also checking interest group checkboxes.
  $showSubscribeCheckbox = TRUE;
  if (!$is_default_value_widget && $show_interest_groups && $hide_subscribe_checkbox && $at_least_one_interest_group && $this
    ->memberIsUnsubscribed($mailchimp_list_id, $email)) {
    $showSubscribeCheckbox = FALSE;
  }
  return $showSubscribeCheckbox;
}