public function CampaignMonitorSubscribeForm::buildForm in Campaign Monitor 8.2
Same name and namespace in other branches
- 8 src/Form/CampaignMonitorSubscribeForm.php \Drupal\campaignmonitor\Form\CampaignMonitorSubscribeForm::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 FormInterface::buildForm
File
- src/
Form/ CampaignMonitorSubscribeForm.php, line 138
Class
- CampaignMonitorSubscribeForm
- Subscribe to a campaignmonitor list.
Namespace
Drupal\campaignmonitor\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $config = []) {
$email = '';
// Try to get the e-mail address from the user object.
if ($this->account
->id() != 0) {
$account = $this->entityTypeManager
->getStorage('user')
->load($this->account
->id());
$email = $account
->get('mail')
->getValue()[0]['value'];
}
// Use of key 'mail' here corresponds with key used in registration form.
$form['mail'] = [
'#type' => 'email',
'#title' => $this
->t('Email'),
'#required' => TRUE,
'#maxlength' => 200,
'#default_value' => $email,
];
switch ($config['list']) {
case 'single':
$form += $this
->singleSubscribeForm($config, $email);
$this
->setFormID($this->formId . '_single');
break;
default:
$form += $this
->userSelectSubscribeForm($form, $form_state, $config, $email);
}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Subscribe'),
];
$form['config'] = [
'#type' => 'hidden',
'#value' => serialize($config),
];
$this->renderer
->addCacheableDependency($form, $config);
return $form;
}