--- lineage_handler_field.inc 2009-10-22 17:37:28.000000000 -0500 +++ lineage_handler_field_new.inc 2009-10-22 17:37:07.000000000 -0500 @@ -4,22 +4,56 @@ * Field handler for Taxonomy: Hierarchy */ class lineage_handler_field extends views_handler_field { + /** + * Provide formatter option. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $field = $this->content_field; + $options = $this->options; + + $formatters = array( + 'raw'=>"Raw lineage entry", + 'hover_link'=>"'Pseudo-link' with indentation and rollover" ); + $format = $options['format'] ? $options['format'] : "hover_link"; + $form['format'] = array( + '#title' => t('Format'), + '#type' => 'select', + '#options' => $formatters, + '#required' => TRUE, + '#default_value' => $format, + '#weight' => 1, + ); + } + function render($values) { $content = $values->{$this->field_alias}; if ($content == '') return ''; - // split lineage string into pieces, i.e. hierarchial path (getting rid of weight numbers, too) - $path = preg_split("(\n[0-9]+-)", "\n".$content); - $s = ''; - // compose the path in readable form - foreach ($path as $a) { - if ($s != '') $s .= ' / '; - $s .= str_replace("\n", '', $a); + $options = $this->options ? $this->options : array(); + $format = $options['format'] ? $options['format'] : ""; + switch ($options['format']) { + case 'raw': + return $content; + break; + + case 'hover_link': + default: + // split lineage string into pieces, i.e. hierarchial path (getting rid of weight numbers, too) + $path = preg_split("(\n[0-9]+-)", "\n".$content); + $s = ''; + // compose the path in readable form + foreach ($path as $a) { + if ($s != '') $s .= ' / '; + $s .= str_replace("\n", '', $a); + } + // output pseudo-link (without href) with hierarchically indented term and full path via title/alt-rollover + return str_repeat('   ', substr_count($content, "\n")-1) + . '' . $a . ''; + break; } - // output pseudo-link (without href) with hierarchically indented term and full path via title/alt-rollover - return str_repeat('   ', substr_count($content, "\n")-1) - . '' . $a . ''; } }