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.

1 call to taxonomy_preview_terms()
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;
}