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.
Create module that uses hook_menu_link_alter to set alter to true for the User Registration page.
function hook_menu_link_alter(&$item) {
if ($item['link_path'] == 'user/register') {
$item['options']['alter'] = TRUE;
}
}
This should invoke hook_translated_menu_link_alter when the User Register link is being processed, however for whatever reason it isn't.
Comment | File | Size | Author |
---|---|---|---|
#5 | Screenshot 2016-08-30 20.43.44.png | 54.13 KB | mchampsee |
#4 | 1_register__in_menu.png | 75.52 KB | stefanos.petrakis@gmail.com |
#4 | 3_register_not_in_menu.png | 68.56 KB | stefanos.petrakis@gmail.com |
#4 | 2_login_in_menu.png | 82.19 KB | stefanos.petrakis@gmail.com |
Comments
Comment #2
stefanos.petrakis@gmail.comThis hook is called when you save a (navigational) menu item, not when you render a link.
If, for example, you create a menu item in one of your menus for this path (user/register) the two hooks will fire after you save the menu item.
The links rendered inside the "User login" block, including the "User Register" link are not menu items, they are simple links, part of the user_login_block form.
Do you have any further details on why this should be classified as a bug? I believe this qualifies for a "Works as designed" status.
Cheers!
Comment #3
mchampsee CreditAttribution: mchampsee at Champsee Solutions, LLC commentedThanks for taking a look. I'm probably not explaining myself properly. Let me flush it out a little more...if you have code that looks like:
In this case, all of the
user/login
menu links will be written asuser/login?destination=node/5
while theuser/register
links won't change.Comment #4
stefanos.petrakis@gmail.comHey, thanks for the update, helps me getting there. :-)
We are still not on the same page though, I am going to insist.
These hooks only apply to links of navigational menu items.
If the link you are targeting (user/register) is not registered (and rendered) in a navigation menu item, the hooks' logic will not apply.
As proof, I am attaching 3 screenshots, this is a standard D7.50 with only your module's code installed.
I added two menu items in the User menu, one for Login (user/login) and one for Register (user/register).
The hooks worked as expected.
The link from the Login block, called "Create new account" (user/register) did not get affected.
So again, the main point is that if the user/register links you are targeting are not affected by your code, it's because they are not (navigational) menu items.
Will keep watching, looking forward to resolving this!
Att1: Register menu item points to user/register, hook logic applies
Att2: Login menu item points to user/login, hook logic applies
Att3: Register link inside the Login block, hook logic does not apply
Comment #5
mchampsee CreditAttribution: mchampsee at Champsee Solutions, LLC commentedWell that's really strange..first off we are on the same page about which link this should affect.
I'm not getting the same results as you as noted on the image below. This is a site that I play around with modules that had a few modules on it which I disabled and still couldn't get it to rewrite the user/register URL. Perhaps its a core module that is either on or off that's causing this? Could you test my code on an existing site that you have in dev? Thanks for all your help thus far.
Comment #6
stefanos.petrakis@gmail.comHey there,
Very glad we are on the same page finally. Found it pretty hard to nail the terms, screenshots speak better.
So, I tested this on the latest HEAD (4a4f50448f1a7e892a9f6df40c4a1dce0cd1d1a4) and it worked for me, same tests I did before.
Maybe time to take turns; could you try it on a vanilla installation?
Cheers and thanks for the patience!
Comment #7
mchampsee CreditAttribution: mchampsee at Champsee Solutions, LLC commentedOn a vanilla install it works. My apologies, I should have explicitly done that first. I'll try to isolate to see if its a particular module or what is causing that behavior.
Comment #8
stefanos.petrakis@gmail.comNo problem, good luck with the rest.