Commit 1817e78b authored by Daniel Linn's avatar Daniel Linn
Browse files

removed install file and cleaned up

parent 18ed1731
name = Taxonomy Terms with Commas
name = Taxonomy Formatter
description = "Add a formatter to taxonomy terms that allows selection of element type, wrapper type, and separators."
package = Fields
core = 7.x
files[] = taxonomy_formatter.module
files[] = taxonomy_formatter.install
\ No newline at end of file
dependencies[] = taxonomy
\ No newline at end of file
......@@ -16,7 +16,166 @@ function taxtocomma_field_formatter_info() {
'links_option' => FALSE,
'separator_option' => ', ',
'element_option' => '- None -',
'wrapper_option' <?php
/**
* @file
* adds a formatter for taxonomy terms with options to specify element type, wrapper type, and separators
*
*/
/**
* Implements hook_field_formatter_info().
*/
function taxonomy_formatter_field_formatter_info() {
return array(
'taxonomy_term_reference_csv' => array(
'label' => t('Delimited'),
'field types' => array('taxonomy_term_reference'),
'settings' => array(
'links_option' => FALSE,
'separator_option' => ', ',
'element_option' => '- None -',
'wrapper_option' => '- None -',
'element_class' => '',
'wrapper_class' => '',
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function taxonomy_formatter_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
$element['links_option'] = array(
'#type' => 'checkbox',
'#title' => t('Links'),
'#description' => t('When checked terms will be displayed as links'),
'#default_value' => $settings['links_option'],
);
$element['separator_option'] = array(
'#type' => 'textfield',
'#title' => t('Separator'),
'#description' => t('The separator to use, including leading and trailing spaces'),
'#default_value' => $settings['separator_option'],
);
$element['element_option'] = array(
'#type' => 'select',
'#title' => t('Element'),
'#description' => t('The HTML element to wrap each tag in'),
'#default_value' => $settings['element_option'],
'#options' => array(
'- None -' => '- None -',
'span' => 'span',
'h1' => 'h1',
'h2' => 'h2',
'h3' => 'h3',
'h4' => 'h4',
'h5' => 'h5',
'strong' => 'h6',
'em' => 'h7',
),
);
$element['element_class'] = array(
'#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'),
'#description' => t('The HTML element to wrap the entire collection in'),
'#default_value' => $settings['wrapper_option'],
'#options' => array(
'- None -' => '- None -',
'div' => 'div',
'span' => 'span',
'h1' => 'h1',
'h2' => 'h2',
'h3' => 'h3',
'h4' => 'h4',
'h5' => 'h5',
'p' => 'p',
'strong' => 'strong',
'em' => 'em',
),
);
$element['wrapper_class'] = array(
'#type' => 'textfield',
'#title' => t('Wrapper Class'),
'#description' => t('The class assigned to the wrapper'),
'#default_value' => $settings['wrapper_class'],
);
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function taxonomy_formatter_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = t('The Terms will be displayed separated by "@separator"', array('@separator' => $settings['separator_option']));
if ($settings['links_option']) {
$summary .= t('<br>The terms will link to the term pages');
}
if ($settings['element_option']!="- None -") {
$summary .= t('<br>Elements will be wrapped in a "@element" tag', array('@element' => $settings['element_option']));
if (!empty($settings['element_class'])) {
$summary .= t(' with the class of @elemclass', array('@elemclass' => $settings['element_class']));
}
}
if ($settings['wrapper_option']!="- None -") {
$summary .= t('<br>The entire list will be wrapped in a "@wrapper" tag', array('@wrapper' => $settings['wrapper_option']));
if (!empty($settings['wrapper_class'])) {
$summary .= t(' with the class of @wrapclass', array('@wrapclass' => $settings['wrapper_class']));
}
}
return $summary;
}
/**
* Implements hook_field_formatter_view().
*/
function taxonomy_formatter_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$element = array();
$separator = check_plain($settings['separator_option']);
if ($settings['element_option']!='- None -') {
$elementwrap[0] = '<' . $settings['element_option'] . ' class="' . check_plain($settings['element_class']) . '">';
$elementwrap[1] = '</' . $settings['element_option'] . '>';
}
else {
$elementwrap[0] = '';
$elementwrap[1] = '';
}
if ($settings['wrapper_option']!='- None -') {
$wrapper[0] = '<' . $settings['wrapper_option'] . ' class="' . check_plain($settings['wrapper_class']) . '">';
$wrapper[1] = '</' . $settings['wrapper_option'] . '>';
}
else {
$wrapper[0] = '';
$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] . l($actterm[$termid]->name, $uri['path'], $uri['options']) . $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;
}=> '- None -',
'element_class' => '',
'wrapper_class' => '',
),
......@@ -29,7 +188,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'),
......@@ -144,10 +303,10 @@ function taxtocomma_field_formatter_view($entity_type, $entity, $field, $instanc
$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;
$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));
......
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