I want an user configurable boolean view filter, displaying child nodes in an hierarchy based on a value, canDisplayOthers, in the master node. The master/children are joined by a field setID.

I tried to do a self-join, adding a view relationship based on setID, but setID is not in the list of relationship fields.

Using Php, the recipe in:


says to use a handler. My handler would return a boolean, something like:

class mymodule_handler_field_isDisplayable extends views_handler_field {
  * Render the name field.
  public function render($values) {
    $value = $this->get_value($values);
       How can I get current node ID (nid) here?


and a hook_views_data something like:

function mymodule_views_data() {
  // Basic table information.
  $data['mymodule_ToDisplay'] = array(
    'table' => array(
      'group' => t('Global'),
      'base' => array(
        'title' => t('ToDisplay')
    'name' => array(
      'title' => t('ToDisplay'),
      'field' => array(
        'handler' => 'mymodule_handler_field_isDisplayable',
    'filter' => array(
    'handler' => 'views_handler_filter_boolean',
  return $data;

I can't figure out:

  1. in mymodule_views_data, what is this thing called 'table'?
  2. how do I get the setID or current nodeID into the mymodule_handler_field_isDisplayable function?

In curiosity; - what is the minimal hook_views_data? - Where is a good place to find where hook_views* parameters are explained?

I am using drupal7 and views 3

ADDITION 15 July 2014

Geoff, below, kindly mentioned that the problem would be easier if I created a master node content type. I created a masterNodeType content type, containing the fields:

  • setID
  • canDisplay

Now, masterNodeType and childNodeType have the common field, setID, but I can't see setID when I configure the view relationship. How do I get setID, and/or masterNodeType into the view relationship? What is the criteria for those view relationship components?

  • If I understand correctly, you have created a hierarchical setup with master nodes being tagged as master, and you want a view to show only rows of the content type where the master canDisplayOthers is set, for any given setID?
    – Geoff
    Commented Jul 7, 2014 at 15:02
  • This is exactly what I want.
    – Dennis
    Commented Jul 14, 2014 at 5:37
  • Regarding documentation, some comes with Views itself. Download and enable advanced_help and check out the help topics for Views' API and its children.
    – Andy
    Commented Jul 14, 2014 at 9:52
  • One problem I see with this, is that you would need to cycle through ALL nodes of that content type either after a query is run, or worse yet, before the query is run, in order to determine if it's the master, and then adjust the next query to suit it's setID. have you considered using a separate content type for master? would be much more efficient and easier to manage I think.
    – Geoff
    Commented Jul 14, 2014 at 13:10
  • Master content type is a great idea, thanks! I created a separate content type for the master node, but I still cannot see it when I try to create the relationship. Also, thanks for the pointer to the documentation.
    – Dennis
    Commented Jul 15, 2014 at 12:16

1 Answer 1


Thanks to the clues provided by Geoff in a comment, I found the answer.

My mistake, (doing too much work), was to create my own foreign key, test_set_id. Drupal uses node_reference fields for such joins. Using node reference, associated content can be directly accessed after adding the relationship in the set-up view screen, without any code.

I also ended up creating an additional master parent content type, to hold some generic test_set information, and to give the child nodes something to point to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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