1 taxonomy.module taxonomy_implode_tags($tags, $vocabulary_name = NULL)

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

See also

backdrop_explode_tags()

File

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

Code

function taxonomy_implode_tags($tags, $vocabulary_name = NULL) {
  $typed_tags = array();
  foreach ($tags as $tag) {
    // Extract terms belonging to the vocabulary in question.
    if (!isset($vocabulary_name) || $tag->vocabulary == $vocabulary_name) {
      // Make sure we have a completed loaded taxonomy term.
      if (isset($tag->name)) {
        // Commas and quotes in tag names are special cases, so encode 'em.
        if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
          $typed_tags[] = '"' . str_replace('"', '""', $tag->name) . '"';
        }
        else {
          $typed_tags[] = $tag->name;
        }
      }
    }
  }
  return implode(', ', $typed_tags);
}