2

I need often to exclude (or limit to) a custom list of nodes from a view. I used to enter the PHP logic directly in the php argument code text area, but this is getting difficult to mantain. I would like to store the logic in a module or template.php.

What I need is a general approach for returning a list of nids (nid1+nid2+nid3...) in the php argument code of the view. I have tried using the approach described here, but I can make it work only for block displays, not for page displays.

For example, I have a content type where nodes can arbitrarily be restricted to authenticated users using the Content Access module per-node settings. I need to display in a view only those nodes, excluding the ones that are visible to the anonymous users. Since there is no filter for this in views, I have built a simple function to retrieve the node IDs and store them in a variable (nid1+nid2+nid3...).

I am struggling to find out where to put this logic (theme_preprocess_views_view(), custom theme_preprocess_func(), mymodule_preprocess_func(), etc.) in order to be able to use this variable in any view PHP argument code.

TL;DR: I need a general approach for returning a list of nids (nid1+nid2+nid3...) in the PHP argument code of the view, saving the php logic in a module or theme.

2

What you really want is a an "argument default plugin". There are some availible in views itself, one is the php one, which you use already.

It's really not that hard to write. You need the following hooks for it:

  • hook_views_api
  • hook_views_plugins

After this you have to create the plugin and most important write a function called get_argument() which returns the arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.