function theme_textformatter_comma in Text list formatter 8.2
Same name and namespace in other branches
- 7 textformatter.module \theme_textformatter_comma()
Theme function to render comma separated lists.
2 theme calls to theme_textformatter_comma()
- ListFormatter::viewElements in lib/
Drupal/ textformatter/ Plugin/ field/ formatter/ ListFormatter.php - Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
- OutputTest::testOutput in lib/
Drupal/ textformatter/ Tests/ OutputTest.php - Test the general output of the display formatter.
File
- ./
textformatter.module, line 194 - Provide a field formatter to render values as HTML or comma-separated lists.
Code
function theme_textformatter_comma($variables) {
$items = $variables['items'];
$formatter = $variables['formatter'];
$attributes = new Attribute($variables['attributes']);
// Optionally prefix the last item with 'and'.
$last = '';
if ($formatter
->getSetting('comma_and') && count($items) > 1 && !$formatter
->getSetting('comma_override')) {
$last = ' ' . t('and') . ' ' . array_pop($items);
}
// Default comma separator.
$separator = ', ';
//Override if we need to.
if ($formatter
->getSetting('comma_override')) {
$sep = check_plain($formatter
->getSetting('separator_custom'));
$tag = $settings['separator_custom_tag'];
if ($tag) {
$class = $formatter
->getSetting('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 ($formatter
->getSetting('comma_full_stop')) {
$output .= '<span class="textformatter-fullstop">.</span>';
}
// Optionally wrap the list in an HTML tag.
$tag = $formatter
->getSetting('comma_tag');
if ($tag) {
$output = "<{$tag}{$attributes}>{$output}</{$tag}>";
}
return $output;
}