views as CCK node reference filters

Drupal's CCK module supports views to filter the nodes to offer for the node reference field type.

The view can be specified with an argument, but the argument is static to the CCK field definition.

With the following snippet of code in the view arguments code, one can specify something dynamic, in my case part of the URL.

I defined a nodeTypeA that references nodeTypeB nodes. When I call node/add/nodeTypeA and want to limit the offered nodeTypeB nodes, for example by nodeTypeB nid, I call

node/add/nodeTypaA/3425

where nodeTypeA is configured to use View view_filter with %3 in the view argument portion. The View filters all nodeTypeB nodes and has as argument the Node ID. The arguments code contains

if(isset($args) && strpos($args[0], '%') === 0)
{
$first_arg = trim($args[0],'%');
$args[0] = arg($first_arg);
}

which now translates %N into the Nth URL argument and uses that as view argument.

Your rating: None Average: 2.8 (20 votes)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.