View source
<?php
class spaces_handler_field_node extends views_handler_field_node {
function option_definition() {
$options = parent::option_definition();
$options['spaces'] = array(
'default' => array(
'type' => NULL,
'frontpage' => FALSE,
),
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$types = array();
foreach (spaces_types() as $type => $info) {
if (strpos('node/%node', $info['path']) === 0) {
$types["spaces_{$type}"] = $info['title'];
}
}
if (!empty($types)) {
$form['spaces']['#tree'] = TRUE;
$form['spaces']['frontpage'] = array(
'#title' => t('Link to space frontpage'),
'#description' => t('Link a group node to its frontpage instead of its node page.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['spaces']['frontpage']),
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-options-link-to-node' => array(
1,
),
),
);
$form['spaces']['type'] = array(
'#title' => t('Space type'),
'#type' => 'select',
'#options' => $types,
'#default_value' => !empty($this->options['spaces']['type']),
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
'edit-options-spaces-frontpage' => array(
1,
),
),
);
}
}
function render_link($data, $values) {
parent::render_link($data, $values);
if ($data !== NULL && $data !== '' && !empty($this->options['spaces']['frontpage']) && !empty($this->options['spaces']['type'])) {
$this->options['alter']['path'] = url('<front>', array(
'absolute' => TRUE,
'purl' => array(
'provider' => $this->options['spaces']['type'],
'id' => $values->{$this->aliases['nid']},
),
));
}
return $data;
}
}