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
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;
}
-
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– YuseferiNov 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