You are here

function theme_textformatter_comma in Text list formatter 7

Same name and namespace in other branches
  1. 8.2 textformatter.module \theme_textformatter_comma()

Theme function to render comma separated lists.

2 theme calls to theme_textformatter_comma()
TextformatterTestCase::testFormatterOutput in ./textformatter.test
Test the general output of the display formatter.
textformatter_field_formatter_view in ./textformatter.module
Implements hook_field_formatter_view().

File

./textformatter.module, line 316
Provide a field formatter to render values as HTML or comma-separated lists.

Code

function theme_textformatter_comma($variables) {
  $items = $variables['items'];
  $settings = $variables['settings'];
  $attributes = drupal_attributes($variables['attributes']);

  // Optionally prefix the last item with 'and'.
  $last = '';
  if ($settings['textformatter_comma_and'] && count($items) > 1 && !$settings['textformatter_comma_override']) {
    $last = ' ' . t('and') . ' ' . array_pop($items);
  }

  // Default comma separator.
  $separator = ', ';

  //Override if we need to.
  if ($settings['textformatter_comma_override']) {
    $sep = check_plain($settings['textformatter_separator_custom']);
    $tag = $settings['textformatter_separator_custom_tag'];
    if ($tag) {
      $class = $settings['textformatter_separator_custom_class'];
      $separator = "<{$tag} class=\"{$class}\">{$sep}</{$tag}>";
    }
  }

  // Generate a comma-separated list.
  $output = implode($separator, $items) . $last;

  // Optionally follow the list with a '.'.
  if ($settings['textformatter_comma_full_stop']) {
    $output .= '<span class="textformatter-fullstop">.</span>';
  }

  // Optionally wrap the list in an HTML tag.
  $tag = $settings['textformatter_comma_tag'];
  if ($tag) {
    $output = "<{$tag}{$attributes}>{$output}</{$tag}>";
  }
  return $output;
}