Commit 18ed1731 authored by Daniel Linn's avatar Daniel Linn
Browse files

Code clean up

parent 622f91ae
......@@ -3,4 +3,4 @@ description = "Add a formatter to taxonomy terms that allows selection of elemen
package = Fields
core = 7.x
files[] = taxonomy_formatter.module
files[] = taxonomy_formatter.install
files[] = taxonomy_formatter.install
\ No newline at end of file
<?php
/**
* @file
* adds a formatter for taxonomy terms to output as CSV
* adds a formatter for taxonomy terms with options to specify element type, wrapper type, and separators
*
*/
/**
......@@ -30,9 +29,7 @@ function taxtocomma_field_formatter_info() {
function taxtocomma_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
$element = array();
$element['links_option'] = array(
'#type' => 'checkbox',
'#title' => t('Links'),
......@@ -63,11 +60,11 @@ function taxtocomma_field_formatter_settings_form($field, $instance, $view_mode,
),
);
$element['element_class'] = array(
'#type' => 'textfield',
'#title' => t('Element Class'),
'#description' => t('The class assigned to the element'),
'#default_value' => $settings['element_class'],
);
'#type' => 'textfield',
'#title' => t('Element Class'),
'#description' => t('The class assigned to the element'),
'#default_value' => $settings['element_class'],
);
$element['wrapper_option'] = array(
'#type' => 'select',
'#title' => t('Wrapper'),
......@@ -88,12 +85,11 @@ function taxtocomma_field_formatter_settings_form($field, $instance, $view_mode,
),
);
$element['wrapper_class'] = array(
'#type' => 'textfield',
'#title' => t('Wrapper Class'),
'#description' => t('The class assigned to the wrapper'),
'#default_value' => $settings['wrapper_class'],
);
'#type' => 'textfield',
'#title' => t('Wrapper Class'),
'#description' => t('The class assigned to the wrapper'),
'#default_value' => $settings['wrapper_class'],
);
return $element;
}
/**
......@@ -142,21 +138,20 @@ function taxtocomma_field_formatter_view($entity_type, $entity, $field, $instanc
$wrapper[1] = '';
}
$formatted = '';
foreach ($items as $delta => $item) {
$termid = $item['tid'];
$term[] = $termid;
$actterm = entity_load('taxonomy_term', $term);
$uri = entity_uri('taxonomy_term', $actterm[$termid]);
if ($settings['links_option']) {
$formatted .= $elementwrap[0] . '<a href=\'/' . $uri['path'] . '\'>' . check_plain($actterm[$termid]->name) . '</a>' . $elementwrap[1] . $separator;
} else {
$formatted .= $elementwrap[0] . check_plain($actterm[$termid]->name) . $elementwrap[1] . $separator;
}
$termid = $item['tid'];
$term[] = $termid;
$actterm = entity_load('taxonomy_term', $term);
$uri = entity_uri('taxonomy_term', $actterm[$termid]);
if ($settings['links_option']) {
$formatted .= $elementwrap[0] . '<a href=\'/' . $uri['path'] . '\'>' . check_plain($actterm[$termid]->name) . '</a>' . $elementwrap[1] . $separator;
} else {
$formatted .= $elementwrap[0] . check_plain($actterm[$termid]->name) . $elementwrap[1] . $separator;
}
}
$length = strlen($separator);
$formatted = substr($formatted, 0 , -($length));
$formatted = $wrapper[0] . $formatted . $wrapper[1];
$element[0]['#markup'] = $formatted;
return $element;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment