views_plugin_argument_default_nodehierarchy.inc in Node Hierarchy 6.2
Contains the node from URL argument default plugin.
File
includes/views/views_plugin_argument_default_nodehierarchy.incView source
<?php
/**
* @file
* Contains the node from URL argument default plugin.
*/
/**
* Default argument plugin to extract an ancestor node id of the currently active node.
*/
class views_plugin_argument_default_nodehierarchy extends views_plugin_argument_default {
function argument_form(&$form, &$form_state) {
$form['default_argument_nodehierarchy'] = array(
'#title' => t('Ancestor Depth'),
'#type' => 'textfield',
'#default_value' => isset($this->argument->options['default_argument_nodehierarchy']) ? $this->argument->options['default_argument_nodehierarchy'] : -1,
'#description' => t('Specify the depth of the ancestor to use. You can specify from the top of the ancestor chain with a positive integer or from the bottom with a negative integer. For example: 0 would be the top level ancestor, while -1 would be the current node\'s immediate parent.'),
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'radio:options[default_action]' => array(
'default',
),
'radio:options[default_argument_type]' => array(
$this->id,
),
),
'#dependency_count' => 2,
);
}
function get_argument() {
$nid = FALSE;
foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i);
if (!empty($node)) {
$nid = $node->nid;
break;
}
}
if ($nid === FALSE && arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
}
if (is_numeric($nid) && ($ancestors = nodehierarchy_get_node_ancestor_nids($nid))) {
$idx = $this->argument->options['default_argument_nodehierarchy'];
if ($idx < 0) {
$idx = count($ancestors) + $idx - 1;
}
return $ancestors[$idx];
}
return NULL;
}
}
Classes
Name | Description |
---|---|
views_plugin_argument_default_nodehierarchy | Default argument plugin to extract an ancestor node id of the currently active node. |