function taxonomy_preview_terms

6.x taxonomy.module taxonomy_preview_terms($node)

Helper function to convert terms after a preview.

After preview the tags are an array instead of proper objects. This function converts them back to objects with the exception of 'free tagging' terms, because new tags can be added by the user before preview and those do not yet exist in the database. We therefore save those tags as a string so we can fill the form again after the preview.

2 calls to taxonomy_preview_terms()
taxonomy_form_alter in drupal-6.x/modules/taxonomy/taxonomy.module
Implementation of hook_form_alter(). Generate a form for selecting terms to associate with a node. We check for taxonomy_override_selector before loading the full vocabulary, so contrib modules can intercept before hook_form_alter and provide scalable…
taxonomy_link in drupal-6.x/modules/taxonomy/taxonomy.module
Implementation of hook_link().

File

drupal-6.x/modules/taxonomy/taxonomy.module, line 590
Enables the organization of content into categories.

Code

function taxonomy_preview_terms($node) {
  $taxonomy = array();
  if (isset($node->taxonomy)) {
    foreach ($node->taxonomy as $key => $term) {
      unset($node->taxonomy[$key]);
      // A 'Multiple select' and a 'Free tagging' field returns an array.
      if (is_array($term)) {
        foreach ($term as $tid) {
          if ($key == 'tags') {
            // Free tagging; the values will be saved for later as strings
            // instead of objects to fill the form again.
            $taxonomy['tags'] = $term;
          }
          else {
            $taxonomy[$tid] = taxonomy_get_term($tid);
          }
        }
      }
      // A 'Single select' field returns the term id.
      elseif ($term) {
        $taxonomy[$term] = taxonomy_get_term($term);
      }
    }
  }
  return $taxonomy;
}