Which is more efficient - hook_form_alter or hook_menu_alter - for replacing a single page?

jersu's picture

I'm replacing a single page from a contributed module. The page is currently rendered with a call to drupal_get_form() from a path like foo/%node/bar

My first thought was to replace the page with hook_form_alter, unset the form elements, and replace with my own content. But I thought that would require a whole lot of preprocessing on the form that I would just discard.

So, my next thought was to just redirect the path to my own function with hook_menu_alter. But, is this less efficient because of the dynamic nature of the path?

I'm just curious if anyone has experience with this.

Groups:
Login to post comments

The dynamic path shouldn't matter

ksenzee's picture
ksenzee - Fri, 2008-10-31 22:11

This seems like a job for hook_menu_alter. If I understand the API docs right, it's only called when the menu_router table is being rebuilt. That's a lot less overhead than overriding the form every single time.


Two things...

mikeker - Mon, 2008-11-03 21:48
  1. Forms are cached. So, it's true that you'll throw away some preproccessing, but only the first time the form is hit (or after the cache is flushed).

  2. If the original module contributor adds some new functionality to the form you're changing, you won't get this if you make the change through hook_menu_alter.

Just a few other things to consider...

-Mike


very cool

jersu's picture
jersu - Tue, 2008-11-04 19:14

Thanks very much ksenzee and mike!

ksenzee: Yeah, that's kinda what I was wondering. I hadn't really had a chance to dig into the drupal v6 api for the menu system yet. I hadn't been quite sure how the new caching works (especially since $may_cache is now gone).

mike: Yes, good to consider. The module in this instance is Organic Groups, so probably a good chance updates will be made over time.