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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mchampsee created an issue. See original summary.

stefanos.petrakis@gmail.com’s picture

This 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!

mchampsee’s picture

Thanks 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:

function hook_menu_link_alter(&$item) {
  if ($item['link_path'] == 'user/register' || $item['link_path'] == 'user/login') {
    $item['options']['alter'] = TRUE;
  }
}
function hook_translated_menu_link_alter(&$item, $map) {
  if ($item['link_path'] == 'user/register' || $item['link_path'] == 'user/login' ) {
    $item['localized_options']['query'] = array('destination' => 'node/5');
  }
}

In this case, all of the user/login menu links will be written as user/login?destination=node/5 while the user/register links won't change.

stefanos.petrakis@gmail.com’s picture

Hey, 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
Att1

Att2: Login menu item points to user/login, hook logic applies
Att2

Att3: Register link inside the Login block, hook logic does not apply
Att3

mchampsee’s picture

Well 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.

user/register not working

stefanos.petrakis@gmail.com’s picture

Hey 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!

mchampsee’s picture

Status: Active » Closed (works as designed)

On 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.

stefanos.petrakis@gmail.com’s picture

No problem, good luck with the rest.