So I've been digging into the Context and Spaces modules from Development Seed. These are two FANTASTIC modules that essentially, when combined, allow a developer to create a web site "feature" that can be essentially packaged for easily installation and use on multiple websites. For example, we're creating a project collaboration site to be used for our client projects that might include things like messages, files, site documentation, chat, support tasks, etc. The challenge thusfar is that the documentation is rather sparse but there are some great videos that show how to get started. They are great for setting up a demo of the tool but figuring out some pieces proves to be less than simple.
The purpose of this particular blog post is to land one piece of the documentation I wish I had discovered previously (perhaps for submission to the project as a whole). It is particularly related to Context Prefixes. So...here's my use case:
I want to be able to setup a project collaboration website where I can setup "projects" that are really organic groups. I want all of the organic group "projects" to sit under a subdirectory called "projects" (duh) so if I want to go to a particular project, I just go to http://www.domain.com/project/[projectId].
This can be done quite readily using pathauto with organic groups. However, using the Context and Spaces modules as default install, it will redirect any calls to an organic group using a "Group" context to http://www.domain.com/[pathprefix]. pathprefix is specified by a required field when the organic group "project" node is created. This completely pushed me away from what I really want which is the /projects/ path. Luckily, there is a screen under Admin > Build > Context > Context Prefix > Settings.
On a Space Type basis (site, group, etc.) you can set the Prefix Method to be one of three entries: Path, Keyed Pair or Full Domain. Path and Full Domain have some available documentation as follows:
Context prefix allows a URL 'prefix' to set a context. The module has two
different modes; 'path prefixes' and 'full domain'. Both modes set a context
based on a URL, but they pull for different places. The 'path prefix' mode uses
a string prepended to a Drupal URL, very similarly to i18n. If a prefix was
'foo' an path would look like 'foo/node/x'. Each time such a path was access it
would set the context that corresponds to 'foo'. 'Full domain' looks at the
domain being used to access the site, and correspondingly sets a context.
Great! Now we know what Path and Full Domain do. However, we still don't know what Keyed Pair does (and it turns out to be what we need). So here's my definition:
'keyed pair' mode uses a string prepended to a Drupal URL, very similarly to i18n, that includes a key term (e.g. "projects") and node id. If a key was 'foo' and the particular group id was 1, a path would look like 'foo/1/node/x'. Each time such a path was accessed it would set the context that corresponds to the group with a node id of 1.
In order to do this, select "Keyed Pair" from as the "Prefix method" for Group space at Admin > Build > Context > Context Prefix > Settings and click save.