You are here

function node_export_prepare_node in Node export 7.3

Same name and namespace in other branches
  1. 6.3 node_export.module \node_export_prepare_node()

Prepare a single node during export.

3 calls to node_export_prepare_node()
node_export in ./node_export.module
Export nodes.
node_export_dependency_load_dependencies in modules/node_export_dependency/node_export_dependency.module
Recursively load dependencies.
node_export_relation_node_reference_load in modules/node_export_relation/node_export_relation.node_reference.inc
Recursively load node references.

File

./node_export.module, line 406
The Node export module.

Code

function node_export_prepare_node(&$original_node) {

  // Create UUID if it's not there.
  if (!uuid_get_uuid('node', 'nid', $original_node->nid)) {
    $original_node->uuid = uuid_set_uuid('node', 'nid', $original_node->nid);

    // Save it so future node exports are consistent.
    node_save($original_node);
  }
  $node = clone $original_node;

  // Fix taxonomy array
  if (isset($node->taxonomy) && count($node->taxonomy)) {
    $vocabularies = taxonomy_get_vocabularies();
    $new_taxonomy = array();
    foreach ($node->taxonomy as $term) {

      // Free-tagging vocabularies need a different format
      if ($vocabularies[$term->vid]->tags) {
        $new_taxonomy['tags'][$term->vid][] = $term->name;
      }
      else {
        $new_taxonomy[$term->vid][$term->tid] = $term->tid;
      }
    }
    if (isset($new_taxonomy['tags']) && count($new_taxonomy['tags'])) {

      // Comma separate the tags
      foreach ($new_taxonomy['tags'] as $vid => $tags) {
        $new_taxonomy['tags'][$vid] = implode(', ', $tags);
      }
    }
    $node->taxonomy = $new_taxonomy;
  }

  // Attach path to the node.  Drupal doesn't attach this anymore for
  // performance reasons http://drupal.org/node/332333#comment-2163634.
  $node->path = path_load(array(
    'source' => 'node/' . $node->nid,
  ));

  // Fix menu array
  $node->menu = node_export_get_menu($original_node);

  // Remove recursion from the object.
  $node = node_export_remove_recursion($node);

  // Add a parameter to identify this node as coming from D7, might be useful some day.
  $node->node_export_drupal_version = '7';

  // Export file fields.
  node_export_file_field_export($node, $original_node);

  // Let other modules do special fixing up.
  drupal_alter('node_export_node', $node, $original_node);
  return $node;
}