University of Oregon

Drupal 7 Views – Manipulating Args with php

I wanted to pass a string to a view that only accepts an entity id as an argument.
I the past I’d been able to use a string based argument after adding relationships but that wasn’t possible in this case.

So I decided to override the incoming argument during validation and replacing the string with the relevant entity id.

The use case:

I mentioned that the view only takes a entity id (nid) as an argument. That nid isn’t available to me when I call the view, but I do know a ‘location’ that I can associate with entities.
Ideally the town name “Eugene” is passed to the view but the entity id (237) is what’s used in the view.

The key was to call another view from within my contextual filter argument validation field.
There I pass the ‘location’ name argument to another view (nid_from_townname) using php and the views_get_view() function.
That view returns the nid for the entity in question. So then I override the original view’s argument with the nid and we’re in business.

Here’s a screenshot of the (view display’s contextual filter argument) validation field: (more…)

Record Count for Multiple Displays for Drupal 6 Views 2 – Update

Yesterday I posted about displaying record counts for multiple displays in Drupal6 using Views2. Well I’ve found a side effect of that method that overwrites your node title on any page that this method is used.
I posted an update here: http://drupal.org/node/131031#comment-3667720.
All’s well that ends well!
Here’s screen cap. of that block:
Screen shot
(more…)

Record Count for Multiple Displays for Drupal 6 Views 2

*Note: Posted Update Here.

I was trying to summarize the status a site migration and found (once again) that I couldn’t display the record count of a view result.
A number of other folks have been looking to solve that issue too so I found a number of resources and after synthesizing the data I found that you need to use a separate ‘views_get_view()’ call for each display and then use

$view->execute_display('display_name');

I posted examples on the drupal.org forum: Count view query results with footer PHP snippet here: http://drupal.org/node/131031#comment-3658090

Turns out execute_display() is the key to getting multiple display results. Thanks to the view2 docs for that!

(more…)

Drupal: insert view on the front end and backend

I’m a big fan of the insert_view module (http://drupal.org/project/insert_view). It makes it really convenient to add a view without requiring php in your wysiwyg editors. But I came across a scenario where I wanted insert a view with php in a node page for a custom content type. I had a hard time finding the right syntax for Drupal 6 so I thought I’d post it here.
(more…)