0

I have an question about drupal's redirect.

Well I implemented hook_menu for the path: "node/%node/boost".

And I set all callbacks from default node path: "node/%node".

/**
 * Implements hook_menu().
 */
function my_module_menu() {
  $items['node/%node/boost'] = array(
    'title callback' => 'node_page_title',
    'title arguments' => array(1),
    'page callback' => 'node_page_view',
    'page arguments' => array(1),
    'access callback' => 'node_access',
    'access arguments' => array('view', 1),
  );

  return $items;
}

So I would get the node from my custom URL

but I got the redirect to default node URL like "node/123".

Any idea how can I load nodes from the my custom URL?

Thanks

UPD

If I change "page callback" function to the my custom function "my_module_page_view", for example:

/**
 * Callback.
 */
function my_module_page_view($node) {
  return 'Hello Drupal!';
}

I will see the text "Hello Drupal!" on the page with URL "/node/1/boost".

But if I use the next code:

/**
 * Callback.
 */
function my_module_page_view($node) {
  return node_view($node);
}

I will get redirect from "/node/1/boost" to "/node/1"

7
  • Are you saying that you visit node/123/boost, and you are redirected to node/123, or are you saying you want the user redirected from node/123/boost to node/123?
    – avpaderno
    Commented Jul 27, 2016 at 10:22
  • It happens. But I don't need it.
    – slivorezka
    Commented Jul 27, 2016 at 10:25
  • It seems the menu item didn't registered. Did you clear cache after adding this?
    – Jimmy Ko
    Commented Jul 27, 2016 at 10:42
  • I would agree with @JimmyKo, but redirecting from node/1/boost to node/1 when node/1/boost didn't get registered is not the default behavior a plain installation of Drupal 7 has. If I create a node (whose ID is 1) and I visit node/1/random-long-string-no-module-uses, I am not redirected in any way. It could be you installed a module that redirects you when you try to access a non registered route like node/1/boost. That, added to the fact Drupal doesn't recognize node/%node/boost as route could explain the behavior you are noticing.
    – avpaderno
    Commented Jul 27, 2016 at 10:55
  • @kiamlaluno According to my memory, I remember that it would redirect node/1/boost to node/1 if there is no node/1/boost router in the database. boost should become the second parameter of the page callback of node/1 automatically.
    – Jimmy Ko
    Commented Jul 27, 2016 at 10:59

1 Answer 1

0

Well It was a monkey's code in the one custom module: It implements hook_node_view() and, if the path was similar to node/1/bla-bla, it redirected users to node/1.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.