You are here

function taxonomy_preview_terms in Drupal 6

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 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 modules/taxonomy/taxonomy.module
Implementation of hook_link().

File

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);
          }
        }
      }
      elseif ($term) {
        $taxonomy[$term] = taxonomy_get_term($term);
      }
    }
  }
  return $taxonomy;
}