node_export_relation.module 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @file
  4. * The Node export relation module.
  5. *
  6. * Helps maintain relationships between nodes during node export operations.
  7. */
  8. /**
  9. * Callback for node reference settings form.
  10. */
  11. function node_export_relation_form_node_export_settings_alter(&$form, &$form_state, $form_id) {
  12. if (module_exists('node_reference')) {
  13. module_load_include('inc', 'node_export_relation', 'node_export_relation.node_reference');
  14. node_export_relation_settings_form_node_reference($form, $form_state, $form_id);
  15. }
  16. /*
  17. // None of the settings are supported yet.
  18. if (module_exists('og')) {
  19. module_load_include('inc', 'node_export_relation', 'node_export_relation.og');
  20. node_export_relation_settings_form_og($form, $form_state, $form_id);
  21. }
  22. */
  23. }
  24. /**
  25. * Implements hook_node_export_alter().
  26. */
  27. function node_export_relation_node_export_alter(&$nodes, $format) {
  28. if (module_exists('node_reference')) {
  29. module_load_include('inc', 'node_export_relation', 'node_export_relation.node_reference');
  30. if (variable_get('node_export_node_reference_auto_inc', TRUE)) {
  31. $keyed_nodes = array();
  32. foreach ($nodes as $node) {
  33. $keyed_nodes[$node->nid] = $node;
  34. }
  35. // Keyed nodes are important for preventing same node loaded again via references.
  36. foreach (array_keys($keyed_nodes) as $nid) {
  37. node_export_relation_node_reference_load($keyed_nodes, $nid);
  38. }
  39. $nodes = array_values($keyed_nodes);
  40. }
  41. }
  42. if (module_exists('og')) {
  43. module_load_include('inc', 'node_export_relation', 'node_export_relation.og');
  44. // Go through nodes and set UUIDs for their groups.
  45. node_export_relation_og_set_group_uuids($nodes);
  46. }
  47. if (module_exists('taxonomy')) {
  48. module_load_include('inc', 'node_export_relation', 'node_export_relation.taxonomy');
  49. foreach ($nodes as $node) {
  50. node_export_relation_taxonomy_build_term_reference($node);
  51. }
  52. }
  53. }
  54. /**
  55. * Implements hook_node_export_import_alter().
  56. */
  57. function node_export_relation_node_export_import_alter(&$nodes, $format) {
  58. if (module_exists('node_reference')) {
  59. module_load_include('inc', 'node_export_relation', 'node_export_relation.node_reference');
  60. foreach ($nodes as $node) {
  61. node_export_relation_node_reference_map($node->nid, $node->uuid);
  62. }
  63. }
  64. if (module_exists('og')) {
  65. module_load_include('inc', 'node_export_relation', 'node_export_relation.og');
  66. // Now go through the groupes and switch back the UUIDS to actual ids.
  67. node_export_relation_og_set_group_nids($nodes);
  68. }
  69. if (module_exists('taxonomy')) {
  70. module_load_include('inc', 'node_export_relation', 'node_export_relation.taxonomy');
  71. foreach ($nodes as $node) {
  72. node_export_relation_taxonomy_restore_term_reference($node);
  73. }
  74. }
  75. }
  76. /**
  77. * Implements hook_node_export_after_import_alter().
  78. */
  79. function node_export_relation_node_export_after_import_alter(&$nodes, $format) {
  80. if (module_exists('node_reference')) {
  81. module_load_include('inc', 'node_export_relation', 'node_export_relation.node_reference');
  82. // Now that all nodes are imported/updated we can restore the node referenced from UUIDS
  83. // NOTE: This is done because if the node referenced node is new, they we have
  84. // to wait for node to be saved.
  85. node_export_relation_node_reference_update($nodes);
  86. }
  87. }