This module allows a default value for a view argument to be specified based on a piece of contextual data set through the Context module's context_set function. When configuring the default argument, you specify the context namespace and the attribute name, and the value is pulled automatically. This is particularly useful for getting information to Views blocks. This is far less hackish than specifying path arguments via arg().
Example use case
Let's say we have a Views block. It's supposed to list all of the nodes that are nodereferenced to whatever node is specified in the argument to the view like so:
Because there's no good way to send arguments to blocks, the traditional approach is to set the View's "Default argument" parameter to PHP code containing:
...or something similar. It is hackish and terrible to rely on the URL for the current nid -- that approach fails to keep the control hierarchy intact (node/xxx invokes a node controller, and if views is invoked somewhere in that stack, it should not be able to jump all the way up to the node controller to retrieve its arguments -- the node or page controller should supply those arguments).
The proper approach is to allow a URL to invoke a controller (like hook_nodeapi) that then arranges all the data to be displayed in the view. So, in the example given above, you would add a line to your helper module's hook_nodeapi that calls
context_set('namespace', 'attribute', $node->nid);
Then, you can enter the namespace and attribute you chose into the Views plugin, and the nid will be transmitted as an argument to your block.
You can easily use this for string arguments as well; for example, if you need to filter based on node type, you could call context_set('namespace', 'attr', 'blogpost'), etc.
Another applications of this module -- making blocks of reverse node references, i.e., a list of nodes that reference the current one. (if you think of other applications, let me know and I'll be glad to add them!)
- Maintenance status: Actively maintained
- Development status: Maintenance fixes only
- Module categories: Utility, Views
- Reported installs: 411 sites currently report using this module. View usage statistics.
- Downloads: 6,986
- Last modified: December 2, 2014
- Stable releases receive coverage from the Drupal Security Team.
Look for the shield icon below.