hooks after hook_menu is called, but before page rendered
I'm in the process of updating taxonomy_breadcrumb to work with 5.0 and as part of the upgrade I'm making a few improvements to the module. I want to have an opportunity to change the breadcrumb trail after hook_menu has been called, but before the page is rendered in the theme. I'm not able to find any way to do this. Any suggestions? It seems as if I need a hook added right at the end of menu_execute_active_handler() in menu.inc, after call_user_func_array (but before returning). Am I missing something? How can I have a function in my module execute after any other hook_menu's have been executed? In the rare case I'm not overlooking the obvious how to I begin the process of trying to get a new hook added? Thanks! Craig
_craig wrote:
I'm in the process of updating taxonomy_breadcrumb to work with 5.0 and as part of the upgrade I'm making a few improvements to the module. I want to have an opportunity to change the breadcrumb trail after hook_menu has been called, but before the page is rendered in the theme. I'm not able to find any way to do this. Any suggestions?
It seems as if I need a hook added right at the end of menu_execute_active_handler() in menu.inc, after call_user_func_array (but before returning). Am I missing something? How can I have a function in my module execute after any other hook_menu's have been executed?
one way to do that is to adjust the weight for your module. set it to a high number to be last. see the system table for that. this is usually set by the module author in .install file
Thanks Moshe, Your response made me realize I made a subtle, but key omission in my original question. Instead of this:
How can I have a function in my module execute after any other hook_menu's have been executed?
I should have said this:
How can I have a function in my module execute after any other hook_menu ** CALLBACKS ** have been executed?
Also, keep in mind I need my function to be called after callbacks, but BEFORE the page is rendered in the theme (which is why I believe hook_footer doesn't work for me). -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Moshe Weitzman Sent: Wednesday, October 18, 2006 7:38 AM To: development@drupal.org Subject: Re: [development] hooks after hook_menu is called, but before page rendered _craig wrote:
I'm in the process of updating taxonomy_breadcrumb to work with 5.0 and as part of the upgrade I'm making a few improvements to the module. I want to have an opportunity to change the breadcrumb trail after hook_menu has been called, but before the page is rendered in the theme. I'm not able to find any way to do this. Any suggestions?
It seems as if I need a hook added right at the end of menu_execute_active_handler() in menu.inc, after call_user_func_array (but before returning). Am I missing something? How can I have a function in my module execute after any other hook_menu's have been executed?
one way to do that is to adjust the weight for your module. set it to a high number to be last. see the system table for that. this is usually set by the module author in .install file
_craig wrote:
Thanks Moshe, Your response made me realize I made a subtle, but key omission in my original question.
Instead of this:
How can I have a function in my module execute after any other hook_menu's have been executed?
I should have said this:
How can I have a function in my module execute after any other hook_menu ** CALLBACKS ** have been executed?
Also, keep in mind I need my function to be called after callbacks, but BEFORE the page is rendered in the theme (which is why I believe hook_footer doesn't work for me).
-----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Moshe Weitzman Sent: Wednesday, October 18, 2006 7:38 AM To: development@drupal.org Subject: Re: [development] hooks after hook_menu is called, but before page rendered
_craig wrote:
I'm in the process of updating taxonomy_breadcrumb to work with 5.0 and as part of the upgrade I'm making a few improvements to the module. I want to have an opportunity to change the breadcrumb trail after hook_menu has been called, but before the page is rendered in the theme. I'm not able to find any way to do this. Any suggestions?
It seems as if I need a hook added right at the end of menu_execute_active_handler() in menu.inc, after call_user_func_array (but before returning). Am I missing something? How can I have a function in my module execute after any other hook_menu's have been executed?
one way to do that is to adjust the weight for your module. set it to a high number to be last. see the system table for that. this is usually set by the module author in .install file
there is no such hook. perhaps you can tell more about what you are doing and we can suggest an approach, or create a new hook.
I want the opportunity to affect the breadcrumb trail already set by modules that used drupal_set_breadcrumb in their menu callbacks. I want to have a final say on what the breadcrumb will really be. For example, I want to be able to change a breadcrumb that says "Home >> created >> by >> a >> module" to "example.com >> created >> by >> a >> module". Currently taxonomy_breadcrumb works only for nodes and not all paths where breadcrumbs are shown. The HEAD version of my module uses hook_nodeapi to call drupal_set_breadcrumb (hook_menu in 4.7). This strategy works well for node types but doesn't get me anywhere for paths that aren't nodes. This is why I want an opportunity the module have the "final" say on breadcrumbs after all menu callbacks have been called (but before "print theme('page', $return);" in index.php). Again I'll highlight the distinction I missed earlier: I specifically mean menu CALLBACKS and not simply hook_menu calls. Craig -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Moshe Weitzman Sent: Wednesday, October 18, 2006 1:15 PM To: development@drupal.org Subject: Re: [development] hooks after hook_menu CALLBACKS called, but before page rendered _craig wrote:
Thanks Moshe, Your response made me realize I made a subtle, but key omission in my original question.
Instead of this:
How can I have a function in my module execute after any other hook_menu's have been executed?
I should have said this:
How can I have a function in my module execute after any other hook_menu ** CALLBACKS ** have been executed?
Also, keep in mind I need my function to be called after callbacks, but BEFORE the page is rendered in the theme (which is why I believe hook_footer doesn't work for me).
-----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Moshe Weitzman Sent: Wednesday, October 18, 2006 7:38 AM To: development@drupal.org Subject: Re: [development] hooks after hook_menu is called, but before page rendered
_craig wrote:
I'm in the process of updating taxonomy_breadcrumb to work with 5.0 and as part of the upgrade I'm making a few improvements to the module. I want to have an opportunity to change the breadcrumb trail after hook_menu has been called, but before the page is rendered in the theme. I'm not able to find any way to do this. Any suggestions?
It seems as if I need a hook added right at the end of menu_execute_active_handler() in menu.inc, after call_user_func_array (but before returning). Am I missing something? How can I have a function in my module execute after any other hook_menu's have been executed?
one way to do that is to adjust the weight for your module. set it to a high number to be last. see the system table for that. this is usually set by the module author in .install file
there is no such hook. perhaps you can tell more about what you are doing and we can suggest an approach, or create a new hook.
_craig wrote:
I want the opportunity to affect the breadcrumb trail already set by modules that used drupal_set_breadcrumb in their menu callbacks. I want to have a final say on what the breadcrumb will really be. You could always do it in template.php. Here's a snippet of mine: It's not the best solution I suppose, but it works!
function _phptemplate_variables($hook, $vars) { switch ($hook) { case 'page': if (arg(0) == 'forward' && is_numeric(arg(1))) { $node = node_load(arg(1)); _mymodule_project_set_breadcrumb($node, TRUE, array(l(t('Spread the word'), 'promote/'. $node->nid))); $vars['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb()); } ....
Rob Barreca wrote:
_craig wrote:
I want the opportunity to affect the breadcrumb trail already set by modules that used drupal_set_breadcrumb in their menu callbacks. I want to have a final say on what the breadcrumb will really be. You could always do it in template.php. Here's a snippet of mine: It's not the best solution I suppose, but it works!
function _phptemplate_variables($hook, $vars) { switch ($hook) { case 'page': if (arg(0) == 'forward' && is_numeric(arg(1))) { $node = node_load(arg(1)); _mymodule_project_set_breadcrumb($node, TRUE, array(l(t('Spread the word'), 'promote/'. $node->nid))); $vars['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb()); } ....
there are loads of one off ways to do this but the author is looking for a standard mechanism he can employ in his module. we don't have a good solution right now. i propsoed a hook_signal() a while back for events like this but it met resistance.
You could always do it in template.php.
Thanks for the suggestion! I hadn't thought of that. However, I am really trying to keep everything encapsulated in a module without requiring users of the module to change a theme or patch core. I did have one thought but quickly discounted it figuring it would make for REALLY ugly hack: 1. Give the taxonomy_breadcrumb module a weight such that it's hook_menu gets called last. 2. Access the global menu object (hack!) and overwrite each callback with my own (hack!!). I'd make the first callback argument the "real" callback function's name and use arguments 2 - N+1 to contain the original N arguments used by the original callback. 3. In my callback that would ALWAYS get called, I'd then look at the first argument to find the "real" callback to call, and then pass the rest on to the function indicated by the first. Following return to my callback function I'd then be able to do whatever I wanted to the page and be assured I was the last to have control of the breadcrumbs (and anything else on the page). Perhaps it would be better to try and get a new hook put into core? Being relatively new to drupal I'm not sure of the process or historical context of adding hooks to core. Do I simply write an issue and submit a patch--now or after 5.0 is released? Do I need to drum up support for it?
So this hook is the equivalent of an 'alter' (hook_nodeapi('alter'), hook_link_alter(), hook_form_alter()). Meaning it would be a hook_breadcrumb_alter() of some sorts? Moshe, was there an issue for your similar request? Rob Roy Barreca Founder and COO Electronic Insight Corporation http://www.electronicinsight.com rob@electronicinsight.com _craig wrote:
You could always do it in template.php.
Thanks for the suggestion! I hadn't thought of that. However, I am really trying to keep everything encapsulated in a module without requiring users of the module to change a theme or patch core.
I did have one thought but quickly discounted it figuring it would make for REALLY ugly hack:
1. Give the taxonomy_breadcrumb module a weight such that it's hook_menu gets called last. 2. Access the global menu object (hack!) and overwrite each callback with my own (hack!!). I'd make the first callback argument the "real" callback function's name and use arguments 2 - N+1 to contain the original N arguments used by the original callback. 3. In my callback that would ALWAYS get called, I'd then look at the first argument to find the "real" callback to call, and then pass the rest on to the function indicated by the first. Following return to my callback function I'd then be able to do whatever I wanted to the page and be assured I was the last to have control of the breadcrumbs (and anything else on the page).
Perhaps it would be better to try and get a new hook put into core? Being relatively new to drupal I'm not sure of the process or historical context of adding hooks to core. Do I simply write an issue and submit a patch--now or after 5.0 is released? Do I need to drum up support for it?
participants (3)
-
_craig -
Moshe Weitzman -
Rob Barreca