public function RequireLoginSettingsForm::validateForm in Require Login 8.2
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ RequireLoginSettingsForm.php, line 178
Class
- RequireLoginSettingsForm
- Configure Require Login settings for this site.
Namespace
Drupal\require_login\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Validate login and destination paths.
$config_keys = [
'require_login_auth_path',
'require_login_destination_path',
];
foreach ($config_keys as $config_key) {
if ($path = $form_state
->getValue($config_key)) {
$this
->processPathInput($path, $config_key, $form_state);
$form_state
->setValue($config_key, $path);
}
}
// Validate excluded paths.
$excluded_paths = preg_split('/\\r\\n|\\r|\\n/', $form_state
->getValue('require_login_excluded_paths'));
$excluded_paths = array_filter($excluded_paths, [
$this,
'arrayFilterEmpty',
]);
foreach ($excluded_paths as $key => $path) {
if (!empty($path) && $path !== '<front>') {
$this
->processPathInput($path, 'require_login_excluded_paths', $form_state);
$excluded_paths[$key] = $path;
}
}
$form_state
->setValue('require_login_excluded_paths', implode(PHP_EOL, $excluded_paths));
// Validate excluded route names.
$excluded_routes = preg_split('/\\r\\n|\\r|\\n/', $form_state
->getValue('require_login_excluded_routes'));
$excluded_routes = array_filter($excluded_routes, [
$this,
'arrayFilterEmpty',
]);
if (!empty($excluded_routes)) {
$valid_route_names = $this->routeProvider
->getRoutesByNames($excluded_routes);
if ($invalid_route_names = array_diff($excluded_routes, array_keys($valid_route_names))) {
$items = [
'#theme' => 'item_list',
'#prefix' => $this
->t('Missing route names detected. You may remove them if the related modules will not be installed.'),
'#items' => $invalid_route_names,
];
$this
->messenger()
->addWarning(render($items));
}
}
}