Thanks for this little module :)

Is there a simple way to display a Logout link, where the Login link was, when users are logged in?

I thought maybe I could pop in something like the below on about line 44 of
login_popup/src/Plugin/Block/LoginAndRegisterPopup.php

     if (\Drupal::currentUser()->isAuthenticated()) { ?>
  <a href="user/logout">Log out</a>
<?php    }

or possibly

    else  { ?>  <a href="user/logout">Log out</a>
<?php  }

both of which seem to work straight after clearing cache but not after that...
Sorry for my complete ignorance of php - Hopefully this is an easy one to solve!?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

olisb created an issue. See original summary.

Bala.addweb’s picture

Status: Active » Needs review
FileSize
873 bytes

PFA Patch.

Subhransu.addweb’s picture

I Applied the patch and having warning: "warning: 1 line adds whitespace errors."

>> Above patch provides logout button only for login & register block. So, I add logout link in login block and register block separately.

PFA new patch for the same.

Thanks!

JayKandari’s picture

Version: 8.x-1.0 » 2.x-dev
Category: Support request » Feature request
Status: Needs review » Needs work
Issue tags: +DIACWJuly2020

We would need to create a configuration on the blocks itself say a checkbox "Show Logout Link" which will be unchecked by default, When that configuration is checked, then only we show the Logout links.

We would need this for sites which have already implemented this module, so that they don't accidentally see the Logout Links.

akshay_d’s picture

Assigned: Unassigned » akshay_d
akshay_d’s picture

Assigned: akshay_d » Unassigned
Status: Needs work » Needs review
FileSize
6.83 KB

Hi @JayKandari
Updated the login_popup to have the logout link based on the requirement. also i have fixed the phpcs for the module.
please review the code.

JayKandari’s picture

Status: Needs review » Needs work

Thank you @akshay_d for the review.. I have added few feedbacks.
Can you please take a look at them for each of the blocks.

  1. +++ b/src/Plugin/Block/LoginAndRegisterPopup.php
    @@ -79,12 +80,35 @@ class LoginAndRegisterPopup extends BlockBase implements ContainerFactoryPluginI
    +      '#default_value' => isset($config['show_logout_link']) ? $config['show_logout_link'] : '',
    

    Instead of checking `isset()` can we check `!empty()` ?

  2. +++ b/src/Plugin/Block/LoginAndRegisterPopup.php
    @@ -79,12 +80,35 @@ class LoginAndRegisterPopup extends BlockBase implements ContainerFactoryPluginI
    +
    

    Can we also implement the defaultConfiguration() method?

  3. +++ b/src/Plugin/Block/LoginAndRegisterPopup.php
    @@ -79,12 +80,35 @@ class LoginAndRegisterPopup extends BlockBase implements ContainerFactoryPluginI
    +    global $base_url;
    

    Instead of `global $base_url;` can we use `\Drupal::request()->getSchemeAndHttpHost();` something like this?

akshay_d’s picture

Status: Needs work » Needs review
FileSize
12.54 KB

Hi @JayKandari
Updated the patch according to the suggestion please review.

Thanks

akshay_d’s picture

FileSize
12.54 KB

Please ignore the previous patch and consider this patch

Thanks

JayKandari’s picture

Status: Needs review » Needs work

Thank you @akshay_d... Looks good. below 2 minor comments if you can address.
Thanks !!

+++ b/src/Plugin/Block/LoginFormPopup.php
@@ -75,15 +87,47 @@ class LoginFormPopup extends BlockBase implements ContainerFactoryPluginInterfac
+      '#default_value' => !empty($config['show_logout_link']) ? $config['show_logout_link'] : '',

Can the default value be either 0 or FALSE?

+++ b/src/Plugin/Block/LoginFormPopup.php
@@ -75,15 +87,47 @@ class LoginFormPopup extends BlockBase implements ContainerFactoryPluginInterfac
+    $base_url = $request->getSchemeAndHttpHost() . $request->getBasePath();

Can we remove `$request->getBasePath()` section because `$request->getSchemeAndHttpHost()` will generate value like this eg: https://www.example.com/ which is what we require right?

akshay_d’s picture

Status: Needs work » Needs review
FileSize
12.4 KB

Updated all the mentioned changes in one patch
please check

Thanks @JayKandari :)

  • JayKandari committed f3f5b73 on 2.x authored by akshay_d
    Issue #2913332 by akshay_d, dev19.addweb, Dev10.addweb, olisb: Log out...
JayKandari’s picture

Status: Needs review » Fixed

Thanks @akshay_d. Patch Looks good. Commited & Pushed to 2.x branch
Thanks !!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.