class SettingsForm in Multiple E-mail Addresses 2.x
Form builder for the admin settings page.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\multiple_email\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 16 - Contains \Drupal\multiple_email\Form\SettingsForm.
Namespace
Drupal\multiple_email\FormView source
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'multiple_email_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'multiple_email.settings',
'multiple_email.mail',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config_settings = $this
->config('multiple_email.settings');
$config_mail = $this
->config('multiple_email.mail');
$form['hide_field'] = array(
'#type' => 'select',
'#title' => t('Hide E-mail Field'),
'#description' => t('Hides the e-mail field when editing a user'),
'#options' => array(
'No',
'Yes',
),
'#default_value' => $config_settings
->get('hide_field'),
);
$form['edit_emails'] = array(
'#type' => 'select',
'#title' => t('Allow editing of emails'),
'#description' => t('Allows editing of e-mail addresses. It is equivalent to deleting and adding a new e-mail address, as edited emails must be re-confirmed. If enabled, e-mail addresses (excluding primary) may be edited via the multiple e-mail tab.'),
'#options' => array(
'No',
'Yes',
),
'#default_value' => $config_settings
->get('edit_emails'),
);
$form['confirm_attempts'] = array(
'#type' => 'textfield',
'#size' => 4,
'#title' => t('Confirm Attempts'),
'#description' => t('How many times a user enters a confirmation code before a new one is generated. If set to 0, no new codes are sent after the first one.'),
'#default_value' => $config_settings
->get('confirm.attempts'),
);
$form['confirm_deadline'] = array(
'#type' => 'textfield',
'#size' => 4,
'#title' => t('Confirm Days'),
'#description' => t('How many days a user has to enter a confirmation code. If 0, emails pending confirmation do not expire.'),
'#default_value' => $config_settings
->get('confirm.deadline'),
);
$vars = '!username, !site, !email, !confirm_code, !confirm_url, !confirm_deadline';
$form['confirmation_subject'] = array(
'#type' => 'textfield',
'#title' => t('Confirmation E-mail Subject'),
'#description' => t('Customize the subject of the message to be sent when a user adds a new e-mail to their account.') . '<br/>' . t('Available variables are:') . $vars,
'#default_value' => $config_mail
->get('confirmation.subject'),
);
$form['confirmation_body'] = array(
'#type' => 'textarea',
'#title' => t('Confirmation E-mail Body'),
'#description' => t('Customize the body of the message to be sent when a user adds a new e-mail to their account.') . '<br/>' . t('Available variables are:') . $vars,
'#default_value' => $config_mail
->get('confirmation.body'),
);
$form['expiration_subject'] = array(
'#type' => 'textfield',
'#title' => t('Expire E-mail Subject'),
'#description' => t('Customize the subject of the message to be sent when an unconfirmed e-mail address expires.') . '<br/>' . t('Available variables are:') . $vars,
'#default_value' => $config_mail
->get('expiration.subject'),
);
$form['expiration_body'] = array(
'#type' => 'textarea',
'#title' => t('Expire E-mail Body'),
'#description' => t('Customize the body of the message to be sent when an unconfirmed e-mail address expires.') . '<br/>' . t('Available variables are:') . $vars,
'#default_value' => $config_mail
->get('expiration.body'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if (!is_numeric($form_state
->getValue('confirm_attempts'))) {
$form_state
->setErrorByName('confirm_attempts', $this
->t('Confirm attempts must be an number!'));
}
if (!is_numeric($form_state
->getValue('confirm_deadline'))) {
$form_state
->setErrorByName('confirm_deadline', $this
->t('Confirm Days must be an number!'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('multiple_email.settings')
->set('hide_field', (bool) $form_state
->getValue('hide_field'))
->set('edit_emails', (bool) $form_state
->getValue('edit_emails'))
->set('confirm.attempts', (int) $form_state
->getValue('confirm_attempts'))
->set('confirm.deadline', (int) $form_state
->getValue('confirm_deadline'))
->save();
$this
->config('multiple_email.mail')
->set('confirmation.subject', $form_state
->getValue('confirmation_subject'))
->set('confirmation.body', $form_state
->getValue('confirmation_body'))
->set('expiration.subject', $form_state
->getValue('expiration_subject'))
->set('expiration.body', $form_state
->getValue('expiration_body'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
18 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 16 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |