function ctools_book_parent_context in Chaos Tool Suite (ctools) 7
Same name and namespace in other branches
- 6 plugins/relationships/book_parent.inc \ctools_book_parent_context()
 
Return a new context based on an existing context.
1 string reference to 'ctools_book_parent_context'
- book_parent.inc in plugins/
relationships/ book_parent.inc  - Plugin to provide an relationship handler for book parent.
 
File
- plugins/
relationships/ book_parent.inc, line 25  - Plugin to provide an relationship handler for book parent.
 
Code
function ctools_book_parent_context($context, $conf) {
  // If unset it wants a generic, unfilled context, which is just NULL.
  if (empty($context->data)) {
    return ctools_context_create_empty('node');
  }
  if (isset($context->data->book)) {
    if ($conf['type'] == 'top') {
      $nid = $context->data->book['bid'];
    }
    else {
      // Just load the parent book.
      $item = book_link_load($context->data->book['plid']);
      $nid = $item['nid'];
    }
    if (!empty($nid)) {
      // Load the node.
      $node = node_load($nid);
      // Generate the context.
      if (node_access('view', $node)) {
        return ctools_context_create('node', $node);
      }
    }
  }
  else {
    return ctools_context_create_empty('node');
  }
}