views_handler_field_nodehierarchy_parent.inc in Node Hierarchy 6
File
includes/views/views_handler_field_nodehierarchy_parent.inc
View source
<?php
class views_handler_field_nodehierarchy_parent extends views_handler_field {
function init(&$view, &$data) {
parent::init($view, $data);
if (isset($data['link_to_parent']) && $view->base_table != 'node') {
$this->additional_fields[] = 'nid';
$this->nid_field = 'node_nid';
}
else {
$this->nid_field = 'parent';
}
}
function options(&$options) {
parent::options($options);
$options['link_to_parent'] = TRUE;
$options['display_as'] = 'title';
}
function options_form(&$form, &$form_state) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => isset($this->options['label']) ? $this->options['label'] : '',
'#description' => t('The label for this field that will be displayed to end users if the style requires it.'),
);
$form['exclude'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude from display'),
'#default_value' => $this->options['exclude'],
'#description' => t('Check this box to not display this field, but still load it in the view. Use this option to not show a grouping field in each record, or when doing advanced theming.'),
);
$form['display_as'] = array(
'#title' => t('Display this field as'),
'#type' => 'select',
'#options' => array(
'title' => t('Node Parent Title'),
'nid' => t('Node Parent ID'),
),
'#default_value' => $this->options['display_as'],
);
$form['link_to_parent'] = array(
'#title' => t('Link this field to the parent node'),
'#type' => 'checkbox',
'#default_value' => $this->options['link_to_parent'],
);
}
function render_parent($data, $values) {
$out = "";
if (@$this->options['display_as'] === 'nid') {
$out = $data;
}
else {
$parent = node_load($data);
$out = $parent->title;
}
if (!empty($this->options['link_to_parent'])) {
return l($out, "node/" . $data);
}
else {
return $out;
}
}
function render($values) {
return $this
->render_parent(check_plain($values->{$this->field_alias}), $values);
}
}