Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Adding a user login block to registration page is not possible. From user module:
case 0:
// For usability's sake, avoid showing two login forms on one page.
if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
...show block
The condition applies to all non-profile user pages, not only user/login.
Steps to reproduce:
1. Add login block to register page
2. Go to register page
Expected behaviour: login block on registration page
Actual behaviour: no login block.
Comment | File | Size | Author |
---|---|---|---|
#65 | 893868-diff-59-65.txt | 287 bytes | jaxxed |
#65 | Login-block-not-shown-on-user-893868-65.patch | 2.09 KB | jaxxed |
#52 | Login-block-not-shown-on-user-893868-46.patch | 2.07 KB | iMiksu |
#52 | 893868-52-testsonly-shouldfail.patch | 1.28 KB | iMiksu |
#46 | Login-block-not-shown-on-user-46.patch | 818 bytes | yogen.prasad |
Comments
Comment #1
VM CreditAttribution: VM commentedI believe this is a won't fix. I don't see this as a bug. The code comment included there explains why the login block isn't shown.
at user/register. There is a login tab on the register form. The code is doing what it is supposed to do AFAICT.
Comment #2
Jasu_M CreditAttribution: Jasu_M commentedAccording to the comment it tries not to show two login forms, not login form+register form.
I tried it with a theme that does not have tabs, so I didn't see the tab though.
However, I believe having register form + login form on a same page is a valid use case.
Comment #3
VM CreditAttribution: VM commentedregister form can be seen as the login form, especially when no approval or verification on the site is required as this setup automatically logs user in upon registration.
Patches welcome if you would like someone to review the changes you propose.
Comment #4
HongPong CreditAttribution: HongPong commentedIs there a way to override this behavior via a theme? This can quite break a layout when you are depending on the block to fill out a region.
Comment #5
VM CreditAttribution: VM commentedi'd think you could set a static region rather than a conditional one so that the "sidebar" is always there whether a block is enabled or not.
Comment #6
adpo CreditAttribution: adpo commentedi agree with Jasu_M that registration form + login form on a same page is a valid use case.
Comment #7
VM CreditAttribution: VM commentedjust a note that this won't get dealt with directly in 6.19. It would have be dealt with in D7 or probably even D8 if this involves any API change. Thus the thread should likely be moved up stream if you all feel so strongly that this should be implemented. At which point this issue should be turned into a feature request rather than a bug.
Comment #8
ericbroder CreditAttribution: ericbroder commented+1 for this being a valid use case and a legitimate bug. Although the code is working correctly based on its own internal logic, I think from a usability perspective it would be much better to let a themer or site administrator decide how to configure this functionality. This seems like a very restrictive implementation of a well-intentioned idea.
Is there any way to turn off this feature/bug?
See also: Always show the login block (even when logged in)
Comment #9
VM CreditAttribution: VM commentedturn off? without hacking core? doesn't seem like it.
I didn't dig to see if this can be overridden with a custom module either.
I also haven't checked D7 for the same, but someone in this thread that wants a different behavior should check and if it's still an issue this thread should be moved to a version of Drupal that is actively being worked on which isn't D6. Whether a change like this would make it into D7 and backported at this point I can't say. If the behavior wasn't changed in D7, this would likely have to be moved to D8 to be looked at for future versions. Especially if there is no patch being worked on by any one already involved in this thread. At this point there are few eyes to read this as its labeled 6.19 and most core developers are working on D7.
Comment #10
VM CreditAttribution: VM commentedmoving to feature request since the code comments note this was done for usablity. Thus not considered a bug as it's a known issue and specifically implemented with a defined reason.
Comment #11
VM CreditAttribution: VM commentedMoving to Drupal 6.x-dev since code in 6.19 wouldn't be altered. Someone with interest will have to do the rest of the legwork to get this moving in a direction that satisfy's the desire wanted.
Comment #12
ericbroder CreditAttribution: ericbroder commentedThanks for the feedback VM, makes sense.
Comment #13
ericbroder CreditAttribution: ericbroder commentedAnother idea here is to at least have the UI better match the code. While it's nice that the code itself is well commented, a user would have no idea what's going on unless they happen to be sifting through the php in user.module. As far as I know there's no UI content that corresponds to the helpful code comment.
Comment #14
VM CreditAttribution: VM commentedThis thread comes up in a search which users should know how to do. That aside where in the ui
would any of this make sense? Perhaps in the core help.module which is a fairly easy patch for someone wanting to take initiative.
Comment #15
ericbroder CreditAttribution: ericbroder commentedThat's an interesting point, I did find this pretty quickly myself by searching drupal.org. Probably the same page that contains the user login block visibility settings would be a good place to mention that this one particular block has an unusual visibility restriction.
Does anyone know if there are adverse side effects to simply removing this restriction from user module, other than the standard problems that come from hacking core?
Comment #16
ericbroder CreditAttribution: ericbroder commentedI'm attaching two patches for this issue. 893868-allow-user-pages.patch will both allow the user login block on user form pages and also improve the visibility settings UI. 893868-ui-enhancement.patch will only improve the visibility settings UI, but not change visibility functionality.
They both need review, but I prefer the first patch because it allows for greater flexibility. And it seems to work well with the redirect features in Login Destination module: http://drupal.org/project/login_destination
Comment #17
ericbroder CreditAttribution: ericbroder commentedThis issue seems to originate from Revision 1.175 of user.module:
http://drupalcode.org/viewvc/drupal/drupal/modules/user/user.module?view...
http://drupalcode.org/viewvc/drupal/drupal/modules/user/user.module?r1=1...
Comment #19
ericbroder CreditAttribution: ericbroder commentedRerolled the patches, hopefully they test better this time.
Comment #21
ericbroder CreditAttribution: ericbroder commentedTrying again, not sure what the problem is.
Comment #22
ericbroder CreditAttribution: ericbroder commentedOk I guess automated testing is for D7 only: http://drupal.org/node/894166#comment-3693940
Here's another try.
Comment #24
ericbroder CreditAttribution: ericbroder commentedComment #25
jeffreyvddb CreditAttribution: jeffreyvddb commentedSubscribe.
Comment #26
cesarpo CreditAttribution: cesarpo commentedWow, I got stuck by this, though i will try to convince my client that this is a case of better usability, i don't think it is.
Comment #27
picxelplay CreditAttribution: picxelplay commentedSubscribe
Comment #28
skylord CreditAttribution: skylord commentedSubscribe
ps: Surely this behaviour shouldn't be hardcoded - the way it is now is not drupalish from any point of view!
Comment #29
a.ross CreditAttribution: a.ross commentedThere's an easy workaround for this, which I can live with very well. Just create a new block with this as block content:
Then do with the block what you want. Don't forget to enable and use the PHP filter!
Comment #30
Gabriel R. CreditAttribution: Gabriel R. commentedThis should not be hardcoded, indeed. The block visibility options are already available for this kid of control.
The solution at #29 is fine for me, but I pity the n00b.
Comment #31
VM CreditAttribution: VM commentedThis isn't likely to get any traction or be changed until someone figures out whether it's still an issue in Drupal 8.x-dev. Which is where it needs to happen first then backported from there to D7 and D6.
Comment #32
mattf10 CreditAttribution: mattf10 commentedI was just caught out by this. It took me hours of searching before realising that this is a "feature". I must strongly disagree with that assessment - this is definitely a bug. For every other block, it is up to the admin to determine the pages that should display the block, EXCEPT FOR THIS ONE!
If this "feature" is to be kept, then it should be changed so that it doesn't appear on the login page since in that case, the page would display two identical forms. But it is certainly a valid use case to allow the user to login or register (or retrieve forgotten pw) from the same page.
It's this kind of undocumented, hidden "feature" that makes Drupal so frustrating to the novice developer.
Rant over.
Comment #34
sunspikes CreditAttribution: sunspikes commentedJust another workaround for D7, for those who don't want to use PHP code, hack the core or wait for the patch. I have created a sandbox module, download and enable, link: Custom Login Block
Comment #35
mrfelton CreditAttribution: mrfelton commentedThe problem with what is in Drupal core now is that is stops the user login block showing on /user/*, including user/password - where it actually makes sense to show the user login block, as well as multiple other paths under /user/.
Attached is a simple patch that adjusts this so that it actually only prevents the form from showing on /user and /user/register - which is more inline with the comment in the code that states "For usability's sake, avoid showing two login forms on one page.".
I also sort of agree that this kind of hardcoded rule really should not be in the code at all, although in the rare case where you might want to override that behaviour a simple custom block implementation is an easy solution.
Comment #36
a.ross CreditAttribution: a.ross commentedGood point.
I would prefer a patch utilizing hook_block_info() though. Though that might have implications for users who are already using the visibility field.
Comment #38
julien CreditAttribution: julien commented36: 893868-drupal-user-password-block-visibility-D7-36.patch queued for re-testing.
Comment #40
WeAreRonin CreditAttribution: WeAreRonin commentedThanks to #29. A little messy but functional.
Comment #41
lauriiiComment #42
FranCarstens CreditAttribution: FranCarstens commentedI spend hours trying to figure out why this block didn't show up. Enabled, Disabled, Edited Contexts, Views, Block, you name it.
Here's the Drupal 7 code for Comment #29's solution which worked for me.
<?php print(drupal_render(drupal_get_form('user_login_block'))); ?>
Just use block settings to limit to roles to anonymous.
Comment #43
lauriiiThis seems more like a bug instead of a feature request
Comment #44
yogen.prasad CreditAttribution: yogen.prasad commentedThis is a bug
Comment #45
yogen.prasad CreditAttribution: yogen.prasad commentedComment #46
yogen.prasad CreditAttribution: yogen.prasad commentedThere was a access check in code which checks login block should not shown on register url, here is the patch for the bug
Comment #47
Ashutosh.tripathi CreditAttribution: Ashutosh.tripathi as a volunteer commentedTested #46 its working fine.
Comment #48
lauriiiSince this is a bug, we need test coverage for this.
Comment #49
yogen.prasad CreditAttribution: yogen.prasad commentedComment #50
yogen.prasad CreditAttribution: yogen.prasad commentedComment #51
iMiksuSee if I manage to write test for this.
Comment #52
iMiksuI created new test
Drupal\user\Tests\UserBlocksTest::testUserLoginBlockVisibility
I decided to test other paths too:Attached only test to confirm that it would detect this issue, and second patch having #46 fix with the tests.
Comment #54
lauriiiComment #57
jaxxed CreditAttribution: jaxxed at Wunder commentederror: patch failed: core/modules/user/src/Plugin/Block/UserLoginBlock.php:77
error: core/modules/user/src/Plugin/Block/UserLoginBlock.php: patch does not apply
Comment #58
jaxxed CreditAttribution: jaxxed at Wunder commentedComment #59
jaxxed CreditAttribution: jaxxed at Wunder commentedrerolled #52 The changes really only come down to some line-number changes, and a few out of context differences.
Comment #60
jaxxed CreditAttribution: jaxxed at Wunder commentedComment #63
jaxxed CreditAttribution: jaxxed at Wunder commentedlet me try to see what I did wrong there.
Comment #64
jaxxed CreditAttribution: jaxxed at Wunder commentedSo in the test, when the DrupalGet tries to get the markup for the block, this is what is returned:
The test target has this assert:
I will re-target for the .block-user-login-block, which should be sufficient.
Comment #65
jaxxed CreditAttribution: jaxxed at Wunder commentedretargeted the login block assert test. Please check the new targeting (visible in the diff) to corroborate that it makes sense.
Sorry for the lack of interdiff. Diff attached quickly.
Incidentally, I tested this manually, and via automated testing.
Comment #66
biguzis CreditAttribution: biguzis commentedTargeting is okey. One thing - typo on patch file on line 23 hided->hidden, but otherwise i will set RTBC!
Comment #67
iMiksuAfter committing this, lets create a follow-up novice issue for changing that typo.
Comment #68
alexpottNormal bug, fixed with no disruption. Committed 18802aa and pushed to 8.0.x. Thanks!
Should be one line and does not need to be quite so descriptive.