You are here

node_export_relation.module in Node export 6.3

Same filename and directory in other branches
  1. 7.3 modules/node_export_relation/node_export_relation.module

The Node export relation module.

Helps maintain relationships between nodes during node export operations.

File

modules/node_export_relation/node_export_relation.module
View source
<?php

/**
 * @file
 * The Node export relation module.
 *
 * Helps maintain relationships between nodes during node export operations.
 */

/**
 * Implements hook_form_FORM_ID_alter().
 */
function node_export_relation_form_node_export_settings_alter(&$form, &$form_state) {
  if (module_exists('node_reference')) {
    module_load_include('inc', 'node_export_relation', 'node_export_relation.node_reference');
    node_export_relation_settings_form_node_reference($form, $form_state);
  }

  /*
  // None of the settings are supported yet.

  if (module_exists('og')) {
    module_load_include('inc', 'node_export_relation', 'node_export_relation.og');
    node_export_relation_settings_form_og($form, $form_state);
  }
  */
}

/**
 * Implementation of hook_node_export_alter().
 *
 * Maintain node relationships.
 */
function node_export_relation_node_export_alter(&$nodes, $op) {
  if (module_exists('nodereference')) {
    module_load_include('inc', 'node_export_relation', 'node_export_relation.node_reference');
    if ($op == 'export') {

      // Keyed nodes are important for preventing same node loaded again via references.
      $keyed_nodes = array();
      foreach ($nodes as $node) {
        $keyed_nodes[$node->nid] = $node;
      }
      foreach (array_keys($keyed_nodes) as $nid) {
        node_export_relation_node_reference_load($keyed_nodes, $nid);
      }
      $nodes = array_values($keyed_nodes);
    }
    elseif ($op == 'import') {
      foreach ($nodes as $node) {
        node_export_relation_node_reference_map($node->nid, $node->uuid);
      }
    }
    elseif ($op == 'after import') {

      // Now that all nodes are imported/updated we can restore the node referenced from UUIDS
      // NOTE: This is done because if the node referenced node is new, they we have
      // to wait for node to be saved.
      node_export_relation_node_reference_update($nodes);
    }
  }
  if (module_exists('og')) {
    module_load_include('inc', 'node_export_relation', 'node_export_relation.og');
    if ($op == 'export') {

      // Go through nodes and set UUIDs for their groups.
      node_export_relation_og_set_group_uuids($nodes);
    }
    elseif ($op == 'import') {

      // Now go through the groupes and switch back the UUIDS to actual ids.
      node_export_relation_og_set_group_nids($nodes);
    }
  }
}