Hello folks,

I try to configure a feed for each book to display new pages, and let user know when a page have been added in a particular book. Unfortunately if seems that book views module does not export the desired field as an argument.
Book nodes have a bid fied wich is the nid of the book where it belong. This bid field is registered as a relationship with node table. There is a comment in the book.views.inc file that says to use this relation and add the node:id argument. But this does not have the same effect. This selects one particular node, and its parent book node :

SELECT node.nid AS nid, node.title AS node_title
FROM node node
LEFT JOIN book book ON node.nid = book.nid
INNER JOIN node node_book ON book.bid = node_book.nid
WHERE node.nid = 1

I need something like this :

SELECT node.nid AS nid, node.title AS node_title
FROM node node
LEFT JOIN book book ON node.nid = book.nid
INNER JOIN node node_book ON book.bid = node_book.nid
WHERE book.bid = 1

Is it possible to make a module that expose the book.bid field to BOTH relationship AND argument ?
I'd prefer not to modify the drupal core files.

Thanks

Comments

terriea’s picture

Ok solved my problem. I created a simple module with only an implementation of hook_views_data :

function bookrelation_views_data() {
  $data['book_childs']['table']['group'] = t('Book');
  $data['book_childs']['table']['join'] = array(
    'node' => array(
      'table' => 'book',
      'left_field' => 'nid',
      'field' => 'nid',
    )
  );
  $data['book_childs']['bid'] = array(
    'title' => t('Is part of the book'),
    'help' => t('Select every nodes that are part od this book.'),
    'argument' => array(
      'handler' => 'views_handler_argument',
    ),
  );
  return $data;
}

This adds an argument for book in views that selects every node that are part of a particular book.
Hope this can be handy for someone else.