public function SimpleMailSettingsController::buildForm in Simple Mail 8
Same name and namespace in other branches
- 2.0.x src/Controller/SimpleMailSettingsController.php \Drupal\simple_mail\Controller\SimpleMailSettingsController::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/
Controller/ SimpleMailSettingsController.php, line 45
Class
- SimpleMailSettingsController
- Returns responses for Simple Mail module routes.
Namespace
Drupal\simple_mail\ControllerCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['queue_enabled'] = array(
'#type' => 'select',
'#title' => t('Simple Mail Queue'),
'#description' => t('You can disable the queue functionality by setting this option to Disabled.'),
'#default_value' => \Drupal::config('simple_mail.settings')
->get('queue_enabled'),
'#options' => array(
0 => t('Disabled'),
1 => t('Enabled'),
),
);
$form['override'] = array(
'#type' => 'email',
'#title' => t('E-mail override address'),
'#placeholder' => 'john.doe@example.com',
'#description' => t('Enter an e-mail address to have all system emails redirected to it. If empty, e-mail will be delivered normally, to the intended recipient.'),
'#default_value' => \Drupal::config('simple_mail.settings')
->get('override'),
);
// Store the keys we want to save in configuration when form is submitted.
$keys_to_save = array_keys($form);
foreach ($keys_to_save as $key => $key_to_save) {
if (strpos($key_to_save, '#') !== FALSE) {
unset($keys_to_save[$key]);
}
}
$form_state
->setStorage([
'keys' => $keys_to_save,
]);
// For now, manually add submit button. Hopefully, by the time D8 is
// released, there will be something like system_settings_form() in D7.
$form['actions']['#type'] = 'container';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save configuration'),
];
return $form;
}