public function SubscriberForm::form in Simplenews 8
Same name and namespace in other branches
- 8.2 src/Form/SubscriberForm.php \Drupal\simplenews\Form\SubscriberForm::form()
- 3.x src/Form/SubscriberForm.php \Drupal\simplenews\Form\SubscriberForm::form()
Gets the actual form array to be built.
Overrides SubscriptionsFormBase::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ SubscriberForm.php, line 23
Class
- SubscriberForm
- Form controller for the subscriber edit forms.
Namespace
Drupal\simplenews\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/* @var \Drupal\simplenews\SubscriberInterface $subscriber */
$subscriber = $this->entity;
$form['#title'] = $this
->t('Edit subscriber @mail', array(
'@mail' => $subscriber
->getMail(),
));
$form['activated'] = array(
'#title' => t('Status'),
'#type' => 'fieldset',
'#description' => t('Whether the subscription is active or blocked.'),
'#weight' => 15,
);
$form['activated']['status'] = array(
'#type' => 'checkbox',
'#title' => t('Active'),
'#default_value' => $subscriber
->getStatus(),
'#disabled' => !$subscriber
->get('status')
->access('edit'),
);
$language_manager = \Drupal::languageManager();
if ($language_manager
->isMultilingual()) {
$languages = $language_manager
->getLanguages();
foreach ($languages as $langcode => $language) {
$language_options[$langcode] = $language
->getName();
}
$form['language'] = array(
'#type' => 'fieldset',
'#title' => t('Preferred language'),
'#description' => t('The e-mails will be localized in language chosen. Real users have their preference in account settings.'),
'#disabled' => FALSE,
);
if ($subscriber
->getUserId()) {
// Fallback if user has not defined a language.
$form['language']['langcode'] = array(
'#type' => 'item',
'#title' => t('User language'),
'#markup' => $subscriber
->language()
->getName(),
);
}
else {
$form['language']['langcode'] = array(
'#type' => 'select',
'#default_value' => $subscriber
->language()
->getId(),
'#options' => $language_options,
'#required' => TRUE,
);
}
}
return $form;
}