The "CLUMPS" module
Clumps is a module that I have just written and will eventually be releasing. Its currently about 90% finished. The name was hastily chosen from a google search for a synonym to section. It is also still up for debate so feel free to comment if you can think of a good name.
All relatively good ideas start with a relatively complex, or annoying, problem.
A site was required that split off into two separate sides with different paths say /sideone and /sidetwo. Most content is to be different, but some should be shared including menus and menu items. Doesn't sound like a very complicated problem does it? The content that is different will obviously be easy in that you can set the url aliases to /sideone/page1, /sidetwo/page2, etc.
The complicated part comes when you consider how to maintain that context separation of which side you are on for the shared content. In this case the shared content had to be prefixed with the /sideone or /sidetwo. Regardless, there are a couple tricky problems here:
- how do you know which side of the site you were working on once you've gone to one of the shared pages?
- For that matter how do you have a menu display only the relevant items for a particular side as well as the shared items?
- How do you have the shared menu item knowledgeable about the context of which side of the site you are on?
I looked into several modules including, context, spaces, features, tokens; all great modules, but none could do exactly what was needed.
It finally occurred to me, however, there was one module that could do everything I wanted it to do, the i18n(internationalization) module. I could create two newly defined languages (copies of the english language) one that added the language prefix sideone and one with sidetwo then my troubles would be solved!
Aside from the logistics of actually modifying i18n, and the fact it would be a ridiculous hack, the main problem would be that the site would never be able to be multilingual. Definitely not cool.
Instead of hacking apart a great module I decided to create a new module that was based largely off of i18n and that makes use of the handy 'Persistent URL' module api.
Here is what the clumps module can currently do:
- maintains a context using the URL to be free of session dependence. Rather then something like a cookie. The PURL api is used for this, so the portion of the URL, called "modifiers", used to maintain the context can be any of the following: Path, Keyed pair, Full domain, Subdomain, File extension, and User agent. Pretty awesome. Thank you Development Seed for that handy api.
- Multiple modifier based contexts can be active at the same time.
- Context is initiated when the user browses to a URL on the site that contains its modifier. All links on the active page, including menu items, will be altered to contain that modifier. For example, if we have set up a path modifier /sideone and browsed to a page that contains /sideone/... the menu item links will now contain that modifier. /contact-us will now show as /sideone/contact-us and when clicked on, it will still take us to the contact-us node, but the URL will contain the modifier. Thus the context is preserved on shared pages through the URL.
- Adds a "Menu Display Mods" selection area to the menu items edit form for selecting which context/modifiers it should be displayed for. This allows an admin to control the visibility of menu items based on the active modifiers. They are organized by modifier type and multiple can be selected.
- PURL provides a behaviour selection area to the menu item edit form for choosing if menu item paths should be altered according to the active modifier or not. (maintain/discard) This is useful for an item whose path already contains a modifier. By setting the behaviour to 'discard' the menu items path will not be altered by any active modifiers.
Here is still what is needed before the module is officially released:
- Add a admin form for adding modifiers. Currently hard coded.
- Add a block visibility selection based on active modifiers similar to the menu. Currently this can be achieved using the function code
return clumps_display_content( array( 'sideone',/*'sidetwo',*/ ) );in the 'Show if the following PHP code returns TRUE ' block visibility area.
- There are conflicts with the context module that need to be sorted out. 1. Context module takes control over block and menu visibility from clumps. 2. Clumps overrides the Context module's control over active menu item and menu trail. A hack fix has been implemented for not to get around this problem.
- Links written into the body of a node/block will not have their URLs altered. Not sure if there is an efficient way to control this or not.
- Review for potential places to add in hooks.
- In code documentation needs to be added. README.txt.
Check it out
Click here to go to a live example of a clumps site.
below you will find an attached tar of the alpha version. To set up your own modifiers you will have to alter the
$clumps_types array at the top of clumps.module.
As always any feedback is welcome so feel free to comment away.
Best Regards, Jesse Payne