class IpLoginSettingsForm in IP Login 4.x
Configure ip_login settings.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\ip_login\Form\IpLoginSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of IpLoginSettingsForm
1 string reference to 'IpLoginSettingsForm'
File
- src/
Form/ IpLoginSettingsForm.php, line 15
Namespace
Drupal\ip_login\FormView source
class IpLoginSettingsForm extends ConfigFormBase {
/**
* The cache factory.
*
* @var \Drupal\Core\Cache\CacheFactoryInterface
*/
protected $cacheFactory;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/**
* Constructs a PathautoSettingsForm.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Defines the configuration object factory.
* @param \Drupal\Core\Cache\CacheFactoryInterface $cache_factory
* The cache factory.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
*/
public function __construct(ConfigFactoryInterface $config_factory, CacheFactoryInterface $cache_factory, CacheTagsInvalidatorInterface $cache_tags_invalidator) {
parent::__construct($config_factory);
$this->cacheFactory = $cache_factory;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('cache_factory'), $container
->get('cache_tags.invalidator'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ip_login_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'ip_login.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('ip_login.settings');
$form['auto_login'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Login automatically'),
'#description' => $this
->t('When an anonymous user accesses any page of the site, the module will attempt to log them in automatically.'),
'#default_value' => $config
->get('auto_login'),
];
$form['form_login'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Login form'),
'#description' => $this
->t('An additional action link is added to the user login form.'),
'#default_value' => $config
->get('form_login'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$config = $this
->config('ip_login.settings');
$form_state
->cleanValues();
$auto_login = $form_state
->getValue('auto_login');
$form_login = $form_state
->getValue('form_login');
$old_auto_login = $config
->get('auto_login');
$config
->set('auto_login', $auto_login);
$old_form_login = $config
->get('form_login');
$config
->set('form_login', $form_login);
// If the login mode is changed, we need to clear the render cache so the
// auto-login can be attempted on subsequent page loads, if configured.
if ($auto_login != $old_auto_login || $form_login != $old_form_login) {
$this->cacheFactory
->get('render')
->deleteAll();
$this->cacheTagsInvalidator
->invalidateTags([
'ip_login',
]);
// We need to invalidate the container so the middleware services are
// registered based on the settings above.
// @see \Drupal\ip_login\IpLoginServiceProvider::register()
\Drupal::service('kernel')
->invalidateContainer();
}
$config
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
IpLoginSettingsForm:: |
protected | property | The cache factory. | |
IpLoginSettingsForm:: |
protected | property | The cache tags invalidator. | |
IpLoginSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
IpLoginSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
IpLoginSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
IpLoginSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
IpLoginSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
IpLoginSettingsForm:: |
public | function |
Constructs a PathautoSettingsForm. Overrides ConfigFormBase:: |
|
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. | |
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. |