Skip to content
og_subgroups_views_handler_field_parent.inc 911 B
Newer Older
<?php
class og_subgroups_views_handler_field_parent extends views_handler_field {
  function init(&$view, $options) {
    parent::init($view, $options);

    $this->additional_fields = array(
      'nid' => array('table' => 'node', 'field' => 'nid'),
    );
  }
  
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    // Add the option to link to the group
    $form['link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Link to the parent group'),
      '#default_value' => isset($this->options['link']) ? $this->options['link'] : 1,
    );
  }
  
  function render($value) {
    og_subgroups_include('tree');
    if ($parent = og_subgroups_get_group_parent($value)) {
      if (!$this->options['link']) {
        return $parent->title;
      }
      else {
        return l($parent->title, "node/{$parent->nid}");
      }
    }
    return NULL;
  }
}