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

neclimdul - April 16, 2008 - 17:21

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.

AttachmentSize
preprocessor.patch 27.16 KB
preprocessor_modules.zip 148 bytes

#2

neclimdul - April 16, 2008 - 17:54

the real modules directory.

AttachmentSize
preprocessor_modules.tar_.gz 1.53 KB

#3

neclimdul - April 16, 2008 - 23:05
Assigned to:Anonymous» neclimdul
Status:active» needs review

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.

<?php
  template_preprocess_forum_user
($variables);
?>

Instead, we now call this:
<?php
  advanced_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.

AttachmentSize
preprocessor.patch 9.55 KB

#4

neclimdul - May 28, 2008 - 05:04

Finally got around to updating this.

Run down of changes:

  • This patch has better caching.
    • the file include search is cache
    • the preprocessor cache is keyed on the theme now which should be better
  • The preprocessor include is gone in favor of just using the d6_compat include
  • Much better documentation of functions
AttachmentSize
preprocessor.patch 13.81 KB
advanced_forum_includes.tar_.gz 1.76 KB

#5

neclimdul - May 29, 2008 - 01:48

removed "is drupal 5" check from d6_compat file and merged with recent commit.

#6

neclimdul - May 29, 2008 - 01:48

patch...

AttachmentSize
preprocessor.patch 13.57 KB

#7

neclimdul - June 10, 2008 - 17:34

whitespace cleanup caused us to go out of sync.

rerolled.

#8

neclimdul - June 10, 2008 - 17:39

I think the patch got lost in a server hiccup or something. repost.

#9

neclimdul - June 10, 2008 - 20:10

trying again

#10

Michelle - June 11, 2008 - 02:21
Version:5.x-1.x-dev» 6.x-1.x-dev
Status:needs review» reviewed & tested by the community

Comitted to 5.x. Need to port to 6.x.

Michelle

#11

Michelle - June 16, 2008 - 19:53

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

AttachmentSize
advanced_forum.module.txt 33.42 KB

#12

neclimdul - June 19, 2008 - 05:56
Status:reviewed & tested by the community» patch (to be ported)

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

neclimdul - June 19, 2008 - 05:57

dang upload problems! trying again...

#14

Michelle - August 21, 2008 - 22:11
Title:Collect extra vars by a hook implementation» Adapt style plugin system to cover code plugins
Category:feature request» task
Assigned to:neclimdul» Anonymous
Status:patch (to be ported)» active

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

neclimdul - September 5, 2008 - 05:12
Title:Adapt style plugin system to cover code plugins» Collect extra vars by a hook implementation
Assigned to:Anonymous» neclimdul

Finally an updated patch for 6.

And I'm claiming my issue back.

AttachmentSize
advanced_forums_extra_variables_d6_228557.patch 3.8 KB

#16

Michelle - September 7, 2008 - 04:30
Status:active» fixed

Committed, yay!

Thanks!

Michelle

temp

Anonymous (not verified) - September 21, 2008 - 04:34

Automatically closed -- issue fixed for two weeks with no activity.

#17

Anonymous (not verified) - September 21, 2008 - 04:41
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.