protected function MailchimpListsSelectWidget::setupSubscribeCheckbox in Mailchimp 2.x
Parameters
array $element:
FormStateInterface $form_state:
$instance MailchimpListsSubscription:
$email:
$hide_subscribe_checkbox:
$at_least_one_interest_group:
$mailchimp_list_id:
Return value
array
1 call to MailchimpListsSelectWidget::setupSubscribeCheckbox()
- MailchimpListsSelectWidget::formElement in modules/
mailchimp_lists/ src/ Plugin/ Field/ FieldWidget/ MailchimpListsSelectWidget.php - Returns the form for a single field widget.
File
- modules/
mailchimp_lists/ src/ Plugin/ Field/ FieldWidget/ MailchimpListsSelectWidget.php, line 95
Class
- MailchimpListsSelectWidget
- Plugin implementation of the 'mailchimp_lists_select' widget.
Namespace
Drupal\mailchimp_lists\Plugin\Field\FieldWidgetCode
protected function setupSubscribeCheckbox(array $element, FormStateInterface $form_state, MailchimpListsSubscription $instance, $email, $hide_subscribe_checkbox, $at_least_one_interest_group, $mailchimp_list_id) {
$memberStatus = $this
->GetMemberStatus($instance, $email);
if ($memberStatus == 'pending') {
// If member status is pending then don't show the subscribe
// checkbox. The user has already attempted to subscribe and
// must check their email to complete the subscription process.
// That means they are neither fully subscribed nor unsubscribed.
return $element;
}
$subscribe_default = $this
->getSubscribeDefault($instance, $email);
$subscribe_checkbox_label = $this->fieldDefinition
->getSetting('subscribe_checkbox_label');
$element['subscribe'] = [
'#title' => $subscribe_checkbox_label ?: $this
->t('Subscribe'),
'#type' => 'checkbox',
'#default_value' => $subscribe_default ? TRUE : $this->fieldDefinition
->isRequired(),
'#required' => $this->fieldDefinition
->isRequired(),
'#disabled' => $this->fieldDefinition
->isRequired(),
];
$showSubscribeCheckbox = $this
->subscribeCheckboxShown($form_state, $hide_subscribe_checkbox, $at_least_one_interest_group, $email, $mailchimp_list_id);
if ($showSubscribeCheckbox) {
$element['subscribe']['#access'] = TRUE;
}
else {
$element['subscribe']['#access'] = FALSE;
}
return $element;
}