Collect extra vars by a hook implementation
Heine - February 29, 2008 - 21:50
| Project: | Advanced Forum |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | neclimdul |
| Status: | closed |
Description
At the moment advanced_forum_extravars collects information from a number of hardcoded modules. When this function would invoke a hook (eg hook_advanced_forum_extra_vars) modules that you don't know about can support advanced forum. It also makes it easy to implement advanced forum support in custom modules without resorting to changing the theme.

#1
I came across a similar problem of extending advanced forum for a site. Also, the code base is alpha and quickly changing so its hard to commit too. So, I got some coffee and started hacking along the same lines with the hook.
What I quickly realized was that we where just adding additional preprocessors along the same lines as MODULE_preprocess_hook work in Drupal 6. So... I ended up ripping code out of the theme registry and the views module include system and ended up with the following patch.
Did I mention there was a lot of coffee involved? Also... it was 3am. Please give it a close eye but I think its a pretty cool solution to the problem that allows for a lot of code reuse in Drupal 6 as well as allowing for optimizations in that environment(use of the native theme registry).
I couldn't figure out how to create a directory for files in a patch so there is a zip with some includes.
#2
the real modules directory.
#3
Ok, sorry, here's a real patch that's review worthy. Not much has changed but there are no whitespace cleanups, extra docs, etc.
A run down of how this actually works.
Part 1) Internal calling, I think theme_forum_user is an easy example and the only place really taking advantage of this functionality. At the begining of this theme function we where manually calling the preprocessor function directly.
<?phptemplate_preprocess_forum_user($variables);
?>
Instead, we now call this:
<?phpadvanced_forum_call_preprocess('forum_user', $variables);
?>
This enters the the code in the preprocessor.inc that very much emulates the theme registry in Drupal 6. So following our example, if we have privatemsg installed it looks for privatemsg_preprocess_forum_user. If I have a module name foobar it we be looking for foobar_preprocess_forum_user. This list is built for each function we call advanced_forum_call_preprocess and then the list is pushed into cache.
Then the functions are called and they add their variables are all merged together.
Part 2) Pluginness. So, how does privatemsg_preprocess_forum_user get added in. Well this is handled in advanced_forum_include. The code is stolen from views and interates through our modules and includes files from certain locations. Views uses this mymodule.views.inc and I've got it setup for advanced forums to use mymodule.forums.inc at the moment but this could be easily changed.
#4
Finally got around to updating this.
Run down of changes:
#5
removed "is drupal 5" check from d6_compat file and merged with recent commit.
#6
patch...
#7
whitespace cleanup caused us to go out of sync.
rerolled.
#8
I think the patch got lost in a server hiccup or something. repost.
#9
trying again
#10
Comitted to 5.x. Need to port to 6.x.
Michelle
#11
I got part way thru porting this a week ago and haven't had time to deal with it since. Here's what I did so far.
Michelle
#12
Finally got around to getting this updated. The only difference between this and michelle's posted code is the cache functions have been updated to the drupal 6 api and the advanced_forum_load_preprocessors function call has been moved earlier in the drupal initialization process to the registry builder will pickup the functions in the includes.
You can see my changes in the second attached patch.
#13
dang upload problems! trying again...
#14
Might as well continue using this issue. We've decided to use the new plugin system for the styles to handle this as well rather than port the patch.
Michelle
#15
Finally an updated patch for 6.
And I'm claiming my issue back.
#16
Committed, yay!
Thanks!
Michelle
temp
Automatically closed -- issue fixed for two weeks with no activity.
#17
Automatically closed -- issue fixed for two weeks with no activity.