You are here

Drupal Bits at Web-Dev: Drupal View with Nodequeue Priority

Sometimes you want a View that follows the internal logic of the filters you set up on the View, but also can have some items hand selected or cultivated to the top of the View. Or perhaps the other way to describe it is a Nodequeue View that is backfilled with some other View based logic so that you end up with a full display regardless of how many items are actually in the Nodequeue.

To do this requires three adjustments to the View (assuming you have already built the normal View logic based on filters that are separate from Nodequeue.

Make the Nodequeue a relationship to the View.

Add the Nodequeu to the sort criteria.

Restructure the filter settings to make it the Nodequeue logic OR the Filter logic.

Example: Nodequeue View with random Backfill

Let's say you have a 3 item View that gets used to display some promoted items on your home page. You want the View to be populated by anything in the Nodequeue and then randomly backfilled with any other item(s) that match some filter criteria if the Nodequeue does not contain three items.

0) To start, create your View that has a maximum of 3 items and set the filter(s) to use your backfil critera (a status of published and limited to whatever entities you are using) and a sort of Global: Random to randomly pick from items that meet the filter criteria.

1) Add your Nodequeue as a relationship.

You want to limited to a specific Nodequeue. The relationship should not be required, or you will not have anything to backfill with.

2) Add the Nodequeue as sort criteria to the View.

Since we want the Nodequeue items to come first, and in order we have to set the sort order in front of the rest of the View sort criteria (which in this case is random).

3) Adjust the filter criteria and break it into logical sections. The first section is the set of filters that must be applied to all items regardless of whether they are in the Nodequeue or not. (the purple region below)

Then you need to create another filter group AND in this group put the items that are either the default logic OR the Nodequeue. The default logic in this case is that audience field matches some criteria. The trick is to set the operator within this filter group to OR.

Now when you add, delete or rearrange items in the Nodequeue the VIew will match the order of the Nodequeue and if you don't have enough items in your que, it will backfill from other items that meet your criteria.

Caching Issues: By default, updating a nodequeue will not cause the cache on the View to expire if the View is cached. If you need the updates to be immediately seen by anonymous users, you can implement a hook_nodequeue_update() to clear the cache.on any changes to that nodequeue.