After numerous discussions with merlinofchaos about the best way to conditionally include the code required for views support, we've settled on the following approach:

  • Put everything in signup_views.inc (as before).
  • Include this from hook_menu(), not hook_init() (since hook_init() is evil).
  • Put stubs of the views hooks we're implementing directly into signup.module, which just include signup_views.inc and invoke the equivalent _signup_views_* private function from signup_views.inc that actually implements the hook. This is the key innovation, since it means that signup_views.inc will always be included whenever views needs the value from a hook, even if hook_menu() hasn't fired yet...

See attached patch. Seems to work great, but I wouldn't mind a little extra testing and confirmation from merlinofchaos that this is The Right Way(tm) to do this. If so, I'll update the appropriate views handbook pages, too.

CommentFileSizeAuthor
signup_views_include.patch.txt3.66 KBdww

Comments

merlinofchaos’s picture

Status: Needs review » Reviewed & tested by the community

+1 from me

dww’s picture

Project: Signup » Views (for Drupal 7)
Version: 5.x-2.x-dev » 5.x-1.x-dev
Component: Views integration » Documentation
Status: Reviewed & tested by the community » Active

Cool, committed to signup's HEAD. Now I just gotta get that handbook page done. Still assigned to me, stay tuned. ;)

moshe weitzman’s picture

Sounds good.

This is exactly the kind of dependency that i was trying to address for D6 with module_invoke() improvements but I must not have explained it well because Crell protested violently. chx liked it, anyway. there is always D7.

sun’s picture

Project: Views (for Drupal 7) » Signup

I don't know what to do with this issue in Views' queue. Moving back to Signup.

dww’s picture

Project: Signup » Views (for Drupal 7)
Assigned: dww » Unassigned
Priority: Normal » Minor

It's a documentation issue about how D5 modules should include views support. The above patch was how I solved it in signup's case (after many discussions w/ Earl), but this issue isn't about signup at all. Perhaps it should just be "won't fixed" since D6 views is much smarter about how its files are loaded, so this is basically a non-issue anymore. But, if anyone was still caring about and maintaining D5 views, it'd be nice to document the approach used by the above patch as the "best practice for D5 views support".

sun’s picture

Status: Active » Closed (won't fix)

I am the one who cares about Views 1.x for now. However, we are in a situation where having documentation issues for it does not make sense IMO, because

- most modules for D5 implemented Views support similar to the patch for Signup, so developers should have sufficient examples
- users are slowly upgrading to D6
- no one really cares about support and documentation issues in this queue
- and I'm actually trying to decrease the size of this queue by 80% ;)

dww’s picture

Fine by me. Cheers. ;)

merlinofchaos’s picture

It turns out that loading conditional support for Views in hook_init() can fail. Sometimes, something will happen in hook_init() (I forget what triggers it, but it happens) that will require a re-build of the Views cache. If this happens before another module's hook_init(), which it can, it can cause that module's views support code to drop out.

For now, the only solution is to recommend that conditional including of views support code happen by proxy; that is, put the hooks in your .module file and have them pass through to hooks in the external file by including the file and calling the same function using a _ prepended to the function name.

dww’s picture

@merlin: FYI: that's exactly what this patch does, and what I was saying would be nice to explain somewhere in the the D5 views developer docs.