Skip to content

Commit 54831e1

Browse files
Merge pull request #10 from OS2Forms/develop
Added settings to hide messages about active NemID session on webform
2 parents 1afb1b2 + 096a6ca commit 54831e1

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
os2forms_nemid.settings:
2+
title: OS2Forms NemID settings
3+
description: Settings for OS2Forms NemID.
4+
route_name: os2web_nemid.settings_form
5+
parent: system.admin_config_system
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
os2web_nemid.settings_form:
2+
path: '/admin/config/system/os2forms_nemid'
3+
defaults:
4+
_title: 'OS2Forms Nemid settings'
5+
_form: 'Drupal\os2forms_nemid\Form\SettingsForm'
6+
requirements:
7+
_permission: 'administer site configuration'

modules/os2forms_nemid/src/EventSubscriber/NemloginRedirectSubscriber.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Core\Session\AccountInterface;
66
use Drupal\Core\Url;
77
use Drupal\os2web_nemlogin\Service\AuthProviderService;
8+
use Drupal\os2forms_nemid\Form\SettingsForm;
89
use Drupal\webform\Entity\Webform;
910
use Symfony\Component\HttpFoundation\RedirectResponse;
1011
use Symfony\Component\HttpKernel\KernelEvents;
@@ -103,7 +104,6 @@ public function redirectToNemlogin(GetResponseEvent $event) {
103104
if (isset($webformNemidSettings['nemlogin_auto_redirect'])) {
104105
$nemlogin_auto_redirect = $webformNemidSettings['nemlogin_auto_redirect'];
105106
}
106-
107107
// Checking if $nemlogin_auto_redirect is on.
108108
if ($nemlogin_auto_redirect) {
109109
// Killing cache so that positive or negative redirect decision is not
@@ -120,11 +120,14 @@ public function redirectToNemlogin(GetResponseEvent $event) {
120120
$event->stopPropagation();
121121
}
122122
else {
123-
\Drupal::messenger()
124-
->addMessage(t('This webform requires a valid NemID authentication and is not visible without it. You currently have an active NemID authentication session. If you do not want to proceed with this webform press <a href="@logout">log out</a> to return back to the front page.', [
125-
'@logout' => $this->nemloginAuthProvider->getLogoutUrl(['query' => ['destination' => Url::fromRoute('<front>')->toString()]])
126-
->toString(),
127-
]));
123+
$settingFormConfig = \Drupal::config(SettingsForm::$configName);
124+
if (!$settingFormConfig->get('os2forms_nemid_hide_active_nemid_session_message')) {
125+
\Drupal::messenger()
126+
->addMessage(t('This webform requires a valid NemID authentication and is not visible without it. You currently have an active NemID authentication session. If you do not want to proceed with this webform press <a href="@logout">log out</a> to return back to the front page.', [
127+
'@logout' => $this->nemloginAuthProvider->getLogoutUrl(['query' => ['destination' => Url::fromRoute('<front>')->toString()]])
128+
->toString(),
129+
]));
130+
}
128131
}
129132
}
130133
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Drupal\os2forms_nemid\Form;
4+
5+
use Drupal\Core\Form\ConfigFormBase;
6+
use Drupal\Core\Form\FormStateInterface;
7+
8+
/**
9+
* Configure os2web_nemid settings for this site.
10+
*/
11+
class SettingsForm extends ConfigFormBase {
12+
13+
/**
14+
* Name of the config.
15+
*
16+
* @var string
17+
*/
18+
public static $configName = 'os2forms_nemid.settings';
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function getFormId() {
24+
return 'os2forms_nemid_settings';
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function getEditableConfigNames() {
31+
return [SettingsForm::$configName];
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function buildForm(array $form, FormStateInterface $form_state) {
38+
// Import settings.
39+
$form['os2forms_nemid_hide_active_nemid_session_message'] = [
40+
'#type' => 'checkbox',
41+
'#title' => t('Hide message about active Nemid session, if it exists.'),
42+
'#description' => t('If checked, meessage aboout active NemID session will not shown on webform page'),
43+
'#default_value' => $this->config(SettingsForm::$configName)
44+
->get('os2forms_nemid_hide_active_nemid_session_message'),
45+
];
46+
47+
return parent::buildForm($form, $form_state);
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
public function submitForm(array &$form, FormStateInterface $form_state) {
54+
$values = $form_state->getValues();
55+
56+
$config = $this->config(SettingsForm::$configName);
57+
foreach ($values as $key => $value) {
58+
$config->set($key, $value);
59+
}
60+
$config->save();
61+
62+
parent::submitForm($form, $form_state);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)