class SettingsForm in Notify 8
Same name and namespace in other branches
- 2.0.x src/Form/SettingsForm.php \Drupal\notify\Form\SettingsForm
- 1.0.x src/Form/SettingsForm.php \Drupal\notify\Form\SettingsForm
Defines a form that configures forms module settings.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\notify\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 20
Namespace
Drupal\notify\FormView source
class SettingsForm extends ConfigFormBase {
/**
* Drupal\Core\Session\AccountProxyInterface definition.
*
* @var AccountProxyInterface $currentUser
*/
protected $currentUser;
/**
* Drupal\Core\Messenger\MessengerInterface definition.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Class constructor.
*
* @param ConfigFactoryInterface $config_factory
* The config factory.
* @param AccountProxyInterface $current_user
* The current user.
* @param MessengerInterface $messenger
* The core messenger service.
*/
public function __construct(ConfigFactoryInterface $config_factory, AccountProxyInterface $current_user, MessengerInterface $messenger) {
parent::__construct($config_factory);
$this->currentUser = $current_user;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('current_user'), $container
->get('messenger'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'notify_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'notify.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('notify.settings');
$period = [
300 => \Drupal::service('date.formatter')
->formatInterval(300),
600 => \Drupal::service('date.formatter')
->formatInterval(600),
900 => \Drupal::service('date.formatter')
->formatInterval(900),
1800 => \Drupal::service('date.formatter')
->formatInterval(1800),
3600 => \Drupal::service('date.formatter')
->formatInterval(3600),
10800 => \Drupal::service('date.formatter')
->formatInterval(10800),
21600 => \Drupal::service('date.formatter')
->formatInterval(21600),
43200 => \Drupal::service('date.formatter')
->formatInterval(43200),
86400 => \Drupal::service('date.formatter')
->formatInterval(86400),
172800 => \Drupal::service('date.formatter')
->formatInterval(172800),
259200 => \Drupal::service('date.formatter')
->formatInterval(259200),
604800 => \Drupal::service('date.formatter')
->formatInterval(604800),
1209600 => \Drupal::service('date.formatter')
->formatInterval(1209600),
2419200 => \Drupal::service('date.formatter')
->formatInterval(2419200),
-1 => $this
->t('Never'),
];
$attempts = [
0 => $this
->t('Disabled'),
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
15 => 15,
20 => 20,
];
$batch = [
2 => 2,
3 => 3,
10 => 10,
20 => 20,
50 => 50,
100 => 100,
200 => 200,
400 => 400,
];
$form['notify_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('E-mail notification settings'),
'#collapsible' => TRUE,
];
$form['notify_settings']['notify_period'] = [
'#type' => 'select',
'#title' => $this
->t('Send notifications every'),
'#default_value' => $config
->get('notify_period'),
'#options' => $period,
'#description' => $this
->t('How often should new content notifications be sent? Requires cron to be running at least this often.'),
];
$form['notify_settings']['notify_send_hour'] = [
'#type' => 'select',
'#title' => $this
->t('Hour to Send Notifications'),
'#description' => $this
->t('Specify the hour (24-hour clock) in which notifications should be sent, if the frequency is one day or greater.'),
'#default_value' => $config
->get('notify_send_hour'),
'#options' => [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
],
];
$form['notify_settings']['notify_attempts'] = [
'#type' => 'select',
'#title' => $this
->t('Number of failed sends after which notifications are disabled'),
'#default_value' => $config
->get('notify_attempts'),
'#options' => $attempts,
];
$form['notify_settings']['notify_batch'] = [
'#type' => 'select',
'#title' => $this
->t('Maximum number of notifications to send out per cron run'),
'#description' => $this
->t('The maximum number of notification e-mails to send in each pass of a cron maintenance task. If necessary, reduce the number of items to prevent resource limit conflicts.'),
'#default_value' => $config
->get('notify_batch'),
'#options' => $batch,
];
$form['notify_settings']['notify_include_updates'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Include updated posts in notifications'),
'#return_value' => 1,
'#default_value' => $config
->get('notify_include_updates'),
];
$form['notify_settings']['notify_unpublished'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Administrators shall be notified about unpublished content of tracked types'),
'#return_value' => 1,
'#default_value' => $config
->get('notify_unpublished'),
];
$form['notify_settings']['notify_watchdog'] = [
'#type' => 'radios',
'#title' => $this
->t('Watchdog log level'),
'#default_value' => $config
->get('notify_watchdog'),
'#options' => [
$this
->t('All'),
$this
->t('Failures+Summary'),
$this
->t('Failures'),
$this
->t('Nothing'),
],
'#description' => $this
->t('This setting lets you specify how much to log.'),
];
$form['notify_settings']['notify_weightur'] = [
'#type' => 'textfield',
'#title' => $this
->t('Weight of notification field in user registration form'),
'#default_value' => $config
->get('notify_weightur'),
'#size' => 3,
'#maxlength' => 5,
'#description' => $this
->t('The weight you set here will determine the position of the notification field when it appears in the user registration form.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('notify.settings')
->set('notify_period', $values['notify_period'])
->set('notify_send_hour', $values['notify_send_hour'])
->set('notify_attempts', $values['notify_attempts'])
->set('notify_batch', $values['notify_batch'])
->set('notify_include_updates', $values['notify_include_updates'])
->set('notify_unpublished', $values['notify_unpublished'])
->set('notify_watchdog', $values['notify_watchdog'])
->set('notify_weightur', $values['notify_weightur'])
->save();
$this->messenger
->addMessage($this
->t('Notify admin settings saved.'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
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. Overrides UrlGeneratorTrait:: |
|
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
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:: |
public | function | Gets the messenger. | 29 |
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:: |
protected | property | Drupal\Core\Session\AccountProxyInterface definition. | |
SettingsForm:: |
protected | property |
Drupal\Core\Messenger\MessengerInterface definition. Overrides MessengerTrait:: |
|
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. 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 |
Class constructor. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |