class FloodSettings in Flood settings 8
Class FloodSettings.
@package Drupal\flood_settings\Form
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\flood_settings\Form\FloodSettings
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of FloodSettings
1 string reference to 'FloodSettings'
File
- src/
Form/ FloodSettings.php, line 16
Namespace
Drupal\flood_settings\FormView source
class FloodSettings extends ConfigFormBase {
const SETTINGS_KEY = 'user.flood';
const DEFAULT_IP_LIMIT = 50;
const DEFAULT_IP_WINDOW = 3600;
const DEFAULT_USER_LIMIT = 5;
const DEFAULT_USER_WINDOW = 21600;
/**
* Drupal\Core\Datetime\DateFormatterInterface definition.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* FloodSettings constructor.
*
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* DateFormatterInterface Object.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory service.
*/
public function __construct(DateFormatterInterface $date_formatter, ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
$this->dateFormatter = $date_formatter;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('date.formatter'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return str_replace('.', '_', self::SETTINGS_KEY);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
self::SETTINGS_KEY,
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config(self::SETTINGS_KEY);
$occurrenceLimits = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
20,
30,
40,
50,
75,
100,
125,
150,
200,
250,
500,
];
$durationLimits = [
60,
180,
300,
600,
900,
1800,
2700,
3600,
10800,
21600,
32400,
43200,
86400,
];
$durationLimits_options = $this
->buildOptions($durationLimits);
$durationLimits_options[0] = $this
->t('None (disabled)');
ksort($durationLimits_options);
$form['login'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Login'),
];
$form['login']['uid_only'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Username only'),
'#default_value' => $config
->get('uid_only') ?? FALSE,
'#description' => $this
->t('Register flood events based on the uid only, so they apply for any
IP address. This is the most secure option.'),
];
$form['login']['ip_limit'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (IP) limit'),
'#default_value' => $config
->get('ip_limit') ?? self::DEFAULT_IP_LIMIT,
'#options' => array_combine($occurrenceLimits, $occurrenceLimits),
];
$form['login']['ip_window'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (IP) window'),
'#default_value' => $config
->get('ip_window') ?? self::DEFAULT_IP_WINDOW,
'#options' => $durationLimits_options,
];
$form['login']['user_limit'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (username) limit'),
'#default_value' => $config
->get('user_limit') ?? self::DEFAULT_USER_LIMIT,
'#options' => array_combine($occurrenceLimits, $occurrenceLimits),
];
$form['login']['user_window'] = [
'#type' => 'select',
'#title' => $this
->t('Failed login (username) window'),
'#default_value' => $config
->get('user_window') ?? self::DEFAULT_USER_WINDOW,
'#options' => $durationLimits_options,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ([
'uid_only',
'ip_limit',
'ip_window',
'user_limit',
'user_window',
] as $configKey) {
$this->configFactory
->getEditable(self::SETTINGS_KEY)
->set($configKey, $form_state
->getValue($configKey))
->save();
}
parent::submitForm($form, $form_state);
}
/**
* Provide DateFormatter interval.
*
* @param array $time_intervals
* Intervals time array.
* @param int $granularity
* Ganularity value.
* @param string|null $langcode
* Langcode value.
*
* @return array
* Return an array.
*/
protected function buildOptions(array $time_intervals, $granularity = 2, $langcode = NULL) {
$callback = function ($value) use ($granularity, $langcode) {
return $this->dateFormatter
->formatInterval($value, $granularity, $langcode);
};
return array_combine($time_intervals, array_map($callback, $time_intervals));
}
}
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 | |
FloodSettings:: |
protected | property | Drupal\Core\Datetime\DateFormatterInterface definition. | |
FloodSettings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
FloodSettings:: |
protected | function | Provide DateFormatter interval. | |
FloodSettings:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
FloodSettings:: |
constant | |||
FloodSettings:: |
constant | |||
FloodSettings:: |
constant | |||
FloodSettings:: |
constant | |||
FloodSettings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
FloodSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
FloodSettings:: |
constant | |||
FloodSettings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
FloodSettings:: |
public | function |
FloodSettings constructor. Overrides ConfigFormBase:: |
|
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:: |
protected | property | The messenger. | 29 |
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. | |
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. |