function taxonomy_implode_tags

Implodes a list of tags of a certain vocabulary into a string.

See also

drupal_explode_tags()

1 call to taxonomy_implode_tags()
TaxonomyAutocompleteWidget::formElement in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().

File

drupal/core/modules/taxonomy/taxonomy.module, line 981
Enables the organization of content into categories.

Code

function taxonomy_implode_tags($tags, $vid = NULL) {
  $typed_tags = array();
  foreach ($tags as $tag) {

    // Extract terms belonging to the vocabulary in question.
    if (!isset($vid) || $tag->vid == $vid) {

      // Make sure we have a completed loaded taxonomy term.
      if ($tag instanceof EntityInterface && ($label = $tag
        ->label())) {

        // Commas and quotes in tag names are special cases, so encode 'em.
        if (strpos($label, ',') !== FALSE || strpos($label, '"') !== FALSE) {
          $typed_tags[] = '"' . str_replace('"', '""', $label) . '"';
        }
        else {
          $typed_tags[] = $label;
        }
      }
    }
  }
  return implode(', ', $typed_tags);
}