You are here

function nodehierarchy_views_embed_children in Node Hierarchy 5

Same name and namespace in other branches
  1. 6.3 nodehierarchy_views/nodehierarchy_views.module \nodehierarchy_views_embed_children()
  2. 6 nodehierarchy_views/nodehierarchy_views.module \nodehierarchy_views_embed_children()
  3. 6.2 nodehierarchy_views/nodehierarchy_views.module \nodehierarchy_views_embed_children()
  4. 7.4 nodehierarchy_views/nodehierarchy_views.module \nodehierarchy_views_embed_children()
  5. 7.2 nodehierarchy_views/nodehierarchy_views.module \nodehierarchy_views_embed_children()

Add the embedded children view to the node body if appropriate.

1 call to nodehierarchy_views_embed_children()
nodehierarchy_views_nodeapi in nodehierarchy_views/nodehierarchy_views.module
Implementation of hook_nodeapi().

File

nodehierarchy_views/nodehierarchy_views.module, line 136
Views.module integration for nodehierarchy.module.

Code

function nodehierarchy_views_embed_children(&$node) {
  if ($node->nh_children_view && ($view = views_get_view($node->nh_children_view))) {

    // make sure the first argument is a node hierarchy parent argument
    $first_arg = $view->argument[0];
    if (!$first_arg || $first_arg['type'] !== "parent" && $first_arg['type'] !== "antecedent") {
      array_unshift($view->argument, array(
        'type' => 'parent',
        'argdefault' => '1',
        'title' => '',
        'options' => '',
        'wildcard' => '',
        'wildcard_substitution' => '',
      ));
    }

    // Get the arguments to send to the view.
    $arguments = explode('/', $_GET['q']);

    // First arg will be 'node', remove it.
    array_shift($arguments);

    // The next argument is the nid, this we will pass as the parent,
    // The rest may be added by the view (feed selectors, calendar params etc).
    // Set the url of the view so that filters and arguments work.
    // NB: setting this to just 'node' works since the nid will be added by the
    // argument code in views (first arg is always the nid). This works but may
    // be taking advantage of a non-api side effect and should be treated with
    // caution.
    $view->url = "node";
    $node->content['nodehierarchy_children'] = array(
      "#value" => views_build_view('embed', $view, $arguments, $view->use_pager, $view->nodes_per_page),
      "#weight" => 10,
    );
  }
}