public function MailLoginAdminSettingsForm::buildForm in Mail Login 8.2
Same name and namespace in other branches
- 8 src/Form/MailLoginAdminSettingsForm.php \Drupal\mail_login\Form\MailLoginAdminSettingsForm::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
- src/
Form/ MailLoginAdminSettingsForm.php, line 30
Class
- MailLoginAdminSettingsForm
- Configure Mail Login settings.
Namespace
Drupal\mail_login\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = \Drupal::service('config.factory')
->getEditable('mail_login.settings');
$form['general'] = [
'#type' => 'fieldset',
'#title' => $this
->t('General Configurations'),
'#open' => TRUE,
];
$form['general']['mail_login_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable login by email address'),
'#default_value' => $config
->get('mail_login_enabled'),
'#description' => $this
->t('This option enables login by email address.'),
];
$form['general']['mail_login_email_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Login by email address only'),
'#default_value' => $config
->get('mail_login_email_only'),
'#states' => [
'visible' => [
':input[name="mail_login_enabled"]' => [
'checked' => TRUE,
],
],
],
'#description' => $this
->t('This option disables login by username and forces login by email address only.'),
];
$form['general']['mail_login_override_login_labels'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Override login form'),
'#default_value' => $config
->get('mail_login_override_login_labels'),
'#states' => [
'visible' => [
':input[name="mail_login_enabled"]' => [
'checked' => TRUE,
],
],
],
'#description' => $this
->t('This option allows you to override the login form username title/description.'),
];
$form['general']['mail_login_username_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Login form username/email address label'),
'#default_value' => $config
->get('mail_login_username_title') ? $config
->get('mail_login_username_title') : $this
->t('Login by username/email address'),
'#states' => [
'required' => [
':input[name="mail_login_override_login_labels"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
],
'visible' => [
':input[name="mail_login_override_login_labels"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
':input[name="mail_login_email_only"]' => [
'checked' => FALSE,
],
],
],
'#description' => $this
->t('Override the username field title.'),
];
$form['general']['mail_login_username_description'] = [
'#type' => 'textfield',
'#title' => $this
->t('Login form username/email address description'),
'#default_value' => $config
->get('mail_login_username_description') ? $config
->get('mail_login_username_description') : $this
->t('You can use your username or email address to login.'),
'#states' => [
'required' => [
':input[name="mail_login_override_login_labels"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
],
'visible' => [
':input[name="mail_login_override_login_labels"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
':input[name="mail_login_email_only"]' => [
'checked' => FALSE,
],
],
],
'#description' => $this
->t('Override the username field description.'),
];
$form['general']['mail_login_email_only_title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Login form email address only label'),
'#default_value' => $config
->get('mail_login_email_only_title') ? $config
->get('mail_login_email_only_title') : $this
->t('Login by email address'),
'#states' => [
'required' => [
':input[name="mail_login_email_only"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
],
'visible' => [
':input[name="mail_login_override_login_labels"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
':input[name="mail_login_email_only"]' => [
'checked' => TRUE,
],
],
],
'#description' => $this
->t('Override the username field title.'),
];
$form['general']['mail_login_email_only_description'] = [
'#type' => 'textfield',
'#title' => $this
->t('Login form email address only description'),
'#default_value' => $config
->get('mail_login_email_only_description') ? $config
->get('mail_login_email_only_description') : $this
->t('You can use your email address only to login.'),
'#states' => [
'required' => [
':input[name="mail_login_email_only"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
],
'visible' => [
':input[name="mail_login_override_login_labels"]' => [
'checked' => TRUE,
'visible' => TRUE,
],
':input[name="mail_login_email_only"]' => [
'checked' => TRUE,
],
],
],
'#description' => $this
->t('Override the username field description.'),
];
return parent::buildForm($form, $form_state);
}