2013-09-10

I had the delightful task at work of determining the visibility of a view (in a node variant) based on the value of a boolean field. But it got better! Said boolean field was not on the node that was being viewed, it was on a node that referenced the node being viewed. But wait! It gets better! The referenced node was an organic group, and those references work differently then a usual entity reference! Confused yet? The actual purpose of the exercise was to allow a content manager to control the widget without having to touch the actual panel variant. This prevents confusion on their part, and also the possibility of the page layout being accidentally destroyed. If they want the widget on their page, they check a box.If they don't want it, leave the box unchecked. Simple enough.

First things first: you have to let ctools know that there is a plugin to use. In your custom module (or in my case, in the relevant feature) .module, you need something like this:

Then in your feature (or custom module), create the directory, so you have a my_feature/plugins/access folder structure.

In the access folder, create a new .inc file. For the purposes of this exercise, the field we are using to determine visibility will be called field_widget, so I would call my file field_widget.inc.

You have to start by defining the plugin, so:

Now write the callback:

Because the field is *not* on the node that is currently being viewed, we have to identify the correct home page node.

Now we have to load the node, to access the field_widget value.

Here is where we check the value of field_widget. Being a boolean, if the value is 0, that means the boolean is not checked, and we want to hide the pane.

Here is the whole kit and caboodle:

And there you have it. :)

Tags: 

Drupal Planet

Drupal

Show more