Is there a function available that returns a list of available contexts?
I'm making a simple CCK dropdown to attach to nodes so that they can be associated with a certain context*, and I'm using the following code in the Allowed Values PHP section of the CCK Select widget:
$values = array();
$i = 0;
$results = db_query("select value from {context}");
while ($result = db_fetch_array($results)) {
$values[$result['value']] = $result['value'];
$i++;
}
return $values;
What that does is generates an array of values based on rows in the 'context' table of the database. This works great when my contexts are defined in the database. However, I'm also using Features to export/import contexts, and since Features store context information in code, and not in the database, the above code does not show any of the Feature-defined contexts.
If there were a function that could return a list of all available contexts (or even better: all contexts of a given namespace), that would be ideal. Is there one already?
*Note: I'm not trying activate a context when the node is being viewed, as can be done with the Context UI. Rather, I'm trying to create an easy to use UI element whereby users can assign certain nodes to a context. The nodes can then be loaded using a Views argument based on the CCK field and displayed when you're viewing that context. That's the general idea. Specifically, I'm attaching the CCK field to image galleries, so they can be used to populate a randomly cycling header image block that is specific to certain contexts.
Comments
Comment #1
m.stentaNevermind. I figured it out. The function I was looking for is in context.module:
So I've updated my PHP Allowed Values to:
... and it works great!