You are here

function content_taxonomy_autocomplete_merge_tags in Content Taxonomy 5

Same name and namespace in other branches
  1. 6.2 content_taxonomy_autocomplete.module \content_taxonomy_autocomplete_merge_tags()
  2. 6 content_taxonomy_autocomplete.module \content_taxonomy_autocomplete_merge_tags()

Helper function to merge the tags, to prefill the fields when editing a node.

1 call to content_taxonomy_autocomplete_merge_tags()
content_taxonomy_autocomplete_widget in ./content_taxonomy_autocomplete.module
Implementation of hook_widget().

File

./content_taxonomy_autocomplete.module, line 294
Defines a widget type for content_taxonomy with autocomplete

Code

function content_taxonomy_autocomplete_merge_tags($terms, $vid, $parent = NULL) {
  $typed_terms = array();
  if (!empty($terms)) {
    foreach ($terms as $term) {

      // Extract terms belonging to the vocabulary in question.
      if ($term->vid == $vid) {

        //if ($tid && in_array($term->tid,drupal_map_assoc(array_keys((taxonomy_get_children($tid,$vid)))))) {

        // Commas and quotes in terms are special cases, so encode 'em.
        if (preg_match('/,/', $term->name) || preg_match('/"/', $term->name)) {
          $term->name = '"' . preg_replace('/"/', '""', $term->name) . '"';
        }
        $typed_terms[] = $term->name;

        // }
      }
    }
  }
  return implode(', ', $typed_terms);
}