0

I'm implementing hook_menu to add a new tab to the user account page. I'd like to pass a URL as the page callback (a local URL for an existing page on the site). the page_callback parameters just accepts a function name. How would I go about using that to pass a URL?

1 Answer 1

1

You can use page arguments:

function MYMODULE_menu() {
  $items['foo'] = array(
    'title' => 'Bar',
    'access arguments' => array('access content'),
    'page callback' => 'MYMODULE_baz',
    'page arguments' => array('http://google.com', 'another arg'),
  );

  return $items;
}

function MYMODULE_baz($url, $another_arg) {
  // Do something with $url, e.g. redirect.
  drupal_goto($url);
}

That's quite a contrived example, if you are redirecting, you could shorten that by just using drupal_goto as the callback:

function MYMODULE_menu() {
  $items['foo'] = array(
    'title' => 'Bar',
    'access arguments' => array('access content'),
    'page callback' => 'drupal_goto',
    'page arguments' => array('http://google.com'),
  );

  return $items;
}
4
  • The problem with that implementation is that drupal_goto completely redirects to the page. I want the page embedded in the user account tab. Nov 16, 2015 at 18:37
  • That's pretty straightforward too, you just need to find out what page callback that page is using, along with the arguments. Where does the page you want to embed come from? Custom code? Node? Something else maybe? I should point out I don't think Drupal has a mechanism to proxy another page by URL, so there'll be a small amount of code involved
    – Clive
    Nov 16, 2015 at 18:38
  • @lcdservices I am agree with Clive, It is seems you don't have clear view about mechanism of menu routering in drupal
    – Yuseferi
    Nov 16, 2015 at 20:51
  • It's proving difficult to do that because the other module the page is generated from isn't loaded at the point this tab is called. Nov 16, 2015 at 20:59

Your Answer

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

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