Commit ed7aa05b authored by Kurucz István's avatar Kurucz István
Browse files

Issue #3302137 by omkar-pd, Vighneshh, nevergone: Logout message type

parent cf8386d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
destination: ''
message: ''
message_type: ''
+3 −0
Original line number Diff line number Diff line
@@ -10,3 +10,6 @@ redirect_after_logout.settings:
    message:
      type: text
      label: 'Redirect message.'
    message_type:
      type: string
      label: 'Message Type'
+1 −1
Original line number Diff line number Diff line
@@ -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();
+13 −0
Original line number Diff line number Diff line
@@ -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.
@@ -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();
  }

+27 −2
Original line number Diff line number Diff line
@@ -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);
@@ -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