Once a user is logged-in, the Login block is still visible. I don't see any code to hide it when the user is logged in like there is for D7. Is that job supposed to be somewhere in my custom code?

Comments

zkent created an issue. See original summary.

zkent’s picture

Issue summary: View changes
zkent’s picture

My first Drupal patch. Please let me know if I am doing this right :)

I borrowed code from UserLoginBlock.php in core since it had the exactly functionality I was looking for already in its core login block.

zkent’s picture

Status: Active » Needs review
sanduhrs’s picture

Version: 8.x-1.0-beta2 » 8.x-1.x-dev
Category: Bug report » Feature request
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.06 KB
  1. +++ b/src/Plugin/Block/LoginBlock.php
    @@ -2,11 +2,15 @@
    +use Drupal\Core\Routing\RouteMatchInterface;
    

    Use statements should be in alphabetical order.

  2. +++ b/src/Plugin/Block/LoginBlock.php
    @@ -2,11 +2,15 @@
    +
    

    There must be one blank line after the last USE

  3. +++ b/src/Plugin/Block/LoginBlock.php
    @@ -33,6 +37,14 @@ class LoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
    +
    

    Expected 1 blank line before function

  4. +++ b/src/Plugin/Block/LoginBlock.php
    @@ -75,6 +93,18 @@ class LoginBlock extends BlockBase implements ContainerFactoryPluginInterface {
    +    if ($account->isAnonymous() && !in_array($route_name, array('user.login', 'user.logout'))) {
    

    Short array syntax must be used to define arrays.

Apart from that, this looks very good.
Thanks for your contribution!

  • sanduhrs committed a8c9a9c on 8.x-1.x
    Issue #2857056 by zkent, sanduhrs: Login block shown when logged in
    
sanduhrs’s picture

Status: Reviewed & tested by the community » Fixed

Just committed your patch.

Please stick to the coding standards next time:
https://www.drupal.org/docs/develop/standards/coding-standards

There are tools that maybe helpful for that task:
https://github.com/squizlabs/PHP_CodeSniffer
https://www.drupal.org/project/coder

Thank you!

Status: Fixed » Closed (fixed)

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