Loading config/install/redirect_after_logout.settings.yml +1 −0 Original line number Diff line number Diff line destination: '' message: '' message_type: '' config/schema/redirect_after_logout.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,6 @@ redirect_after_logout.settings: message: type: text label: 'Redirect message.' message_type: type: string label: 'Message Type' src/EventSubscriber/RedirectAfterLogoutSubscriber.php +1 −1 Original line number Diff line number Diff line Loading @@ -159,7 +159,7 @@ class RedirectAfterLogoutSubscriber implements EventSubscriberInterface { if ((bool) $parameter_bag->get('logout-message') && $this->currentUser->isAnonymous()) { $config = $this->configFactory->get('redirect_after_logout.settings'); $logout_message = nl2br($config->get('message')); $this->messenger->addMessage(['#markup' => Xss::filter($this->token->replace($logout_message), ['br'])]); $this->messenger->addMessage(['#markup' => Xss::filter($this->token->replace($logout_message), ['br'])], $config->get('message_type')); } elseif ((bool) $parameter_bag->get('logout-message') && !$this->currentUser->isAnonymous()) { $destination = $this->redirectDestination->getAsArray(); Loading src/Form/RedirectLogoutSettings.php +13 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,17 @@ class RedirectLogoutSettings extends ConfigFormBase { '#description' => $this->t('Tokens are allowed.'), '#default_value' => $config->get('message'), ]; $form['redirect_after_message_type'] = [ '#title' => $this->t('Message Type'), '#description' => $this->t('Message type'), '#type' => 'select', '#options' => [ 'status' => $this->t('Status'), 'warning' => $this->t('Warning'), 'error' => $this->t('Error'), ], '#default_value' => $config->get('message_type'), ]; if ($this->moduleHandler->moduleExists('token')) { // Add the token help to a collapsed fieldset at // the end of the configuration page. Loading Loading @@ -194,6 +205,8 @@ class RedirectLogoutSettings extends ConfigFormBase { $config = $this->config('redirect_after_logout.settings'); $config->set('destination', $form_state->getValue('redirect_after_logout_destination')); $config->set('message', $form_state->getValue('redirect_after_logout_message')); $config->set('message_type', $form_state->getValue('redirect_after_message_type')); $config->save(); } Loading tests/src/Functional/RedirectTest.php +27 −2 Original line number Diff line number Diff line Loading @@ -40,11 +40,11 @@ class RedirectTest extends TestBase { // External path. $edit['edit-redirect-after-logout-destination'] = 'http://example.com/'; $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', FALSE); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', 'status', FALSE); // External path with token. $edit['edit-redirect-after-logout-destination'] = 'http://[site:name].com/'; $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', FALSE); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', 'status', FALSE); // Valid node path. $edit['edit-redirect-after-logout-destination'] = '/foobar-example'; $this->setRedirectConfig($edit); Loading Loading @@ -79,4 +79,29 @@ class RedirectTest extends TestBase { $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, '/foobar-example', nl2br($message)); } /** * Test redirecting with message types. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException */ public function testRedirectingWithMessageType() { $message_types = [ 'status', 'warning', 'error' ]; $this->drupalLogin($this->adminUser); $message = $this->randomMachineName(); $edit = [ 'edit-redirect-after-logout-destination' => '/foobar-example', 'edit-redirect-after-logout-message' => $message, ]; foreach ($message_types as $message_type) { $edit['redirect_after_message_type'] = $message_type; $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, '/foobar-example', $message, $message_type); } } } Loading
config/install/redirect_after_logout.settings.yml +1 −0 Original line number Diff line number Diff line destination: '' message: '' message_type: ''
config/schema/redirect_after_logout.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,6 @@ redirect_after_logout.settings: message: type: text label: 'Redirect message.' message_type: type: string label: 'Message Type'
src/EventSubscriber/RedirectAfterLogoutSubscriber.php +1 −1 Original line number Diff line number Diff line Loading @@ -159,7 +159,7 @@ class RedirectAfterLogoutSubscriber implements EventSubscriberInterface { if ((bool) $parameter_bag->get('logout-message') && $this->currentUser->isAnonymous()) { $config = $this->configFactory->get('redirect_after_logout.settings'); $logout_message = nl2br($config->get('message')); $this->messenger->addMessage(['#markup' => Xss::filter($this->token->replace($logout_message), ['br'])]); $this->messenger->addMessage(['#markup' => Xss::filter($this->token->replace($logout_message), ['br'])], $config->get('message_type')); } elseif ((bool) $parameter_bag->get('logout-message') && !$this->currentUser->isAnonymous()) { $destination = $this->redirectDestination->getAsArray(); Loading
src/Form/RedirectLogoutSettings.php +13 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,17 @@ class RedirectLogoutSettings extends ConfigFormBase { '#description' => $this->t('Tokens are allowed.'), '#default_value' => $config->get('message'), ]; $form['redirect_after_message_type'] = [ '#title' => $this->t('Message Type'), '#description' => $this->t('Message type'), '#type' => 'select', '#options' => [ 'status' => $this->t('Status'), 'warning' => $this->t('Warning'), 'error' => $this->t('Error'), ], '#default_value' => $config->get('message_type'), ]; if ($this->moduleHandler->moduleExists('token')) { // Add the token help to a collapsed fieldset at // the end of the configuration page. Loading Loading @@ -194,6 +205,8 @@ class RedirectLogoutSettings extends ConfigFormBase { $config = $this->config('redirect_after_logout.settings'); $config->set('destination', $form_state->getValue('redirect_after_logout_destination')); $config->set('message', $form_state->getValue('redirect_after_logout_message')); $config->set('message_type', $form_state->getValue('redirect_after_message_type')); $config->save(); } Loading
tests/src/Functional/RedirectTest.php +27 −2 Original line number Diff line number Diff line Loading @@ -40,11 +40,11 @@ class RedirectTest extends TestBase { // External path. $edit['edit-redirect-after-logout-destination'] = 'http://example.com/'; $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', FALSE); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', 'status', FALSE); // External path with token. $edit['edit-redirect-after-logout-destination'] = 'http://[site:name].com/'; $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', FALSE); $this->logoutRedirectHelper($this->regularUser, 'http://example.com/', '', 'status', FALSE); // Valid node path. $edit['edit-redirect-after-logout-destination'] = '/foobar-example'; $this->setRedirectConfig($edit); Loading Loading @@ -79,4 +79,29 @@ class RedirectTest extends TestBase { $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, '/foobar-example', nl2br($message)); } /** * Test redirecting with message types. * * @throws \Behat\Mink\Exception\ElementNotFoundException * @throws \Behat\Mink\Exception\ExpectationException */ public function testRedirectingWithMessageType() { $message_types = [ 'status', 'warning', 'error' ]; $this->drupalLogin($this->adminUser); $message = $this->randomMachineName(); $edit = [ 'edit-redirect-after-logout-destination' => '/foobar-example', 'edit-redirect-after-logout-message' => $message, ]; foreach ($message_types as $message_type) { $edit['redirect_after_message_type'] = $message_type; $this->setRedirectConfig($edit); $this->logoutRedirectHelper($this->regularUser, '/foobar-example', $message, $message_type); } } }