node_export_relation.og.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @file
  4. * The Node export relation OG include.
  5. *
  6. * Helps maintain organic groups relationships between nodes during node export operations.
  7. */
  8. /**
  9. * Callback for OG settings form.
  10. */
  11. function node_export_relation_settings_form_og(&$form, &$form_state) {
  12. $form['og'] = array(
  13. '#type' => 'fieldset',
  14. '#title' => t('Organic groups'),
  15. );
  16. $form['og']['node_export_og_auto_inc'] = array(
  17. '#type' => 'checkbox',
  18. '#title' => t('Automatically OG related related nodes in exports'),
  19. '#default' => variable_get('node_export_og_auto_inc', TRUE),
  20. );
  21. $form['og']['node_export_og_skip'] = array(
  22. '#type' => 'checkbox',
  23. '#title' => t('Skip related OG nodes that cannot be exported'),
  24. '#default' => variable_get('node_export_og_skip', TRUE),
  25. '#description' => t('If this is disabled, node exports will fail if a related OG node cannot be exported, for example if the user performing the export does not have access.'),
  26. );
  27. }
  28. /**
  29. * Go through group nids and put group UUIDs in their place.
  30. */
  31. function node_export_relation_og_set_group_uuids(&$nodes) {
  32. foreach ($nodes as &$node) {
  33. if (!empty($node->og_groups)) {
  34. foreach ($node->og_groups as $key => $group_nid) {
  35. $group_uuid = uuid_get_uuid('node', 'nid', $group_nid);
  36. // Create uuid if it doesn't exists
  37. if (empty($group_uuid)) {
  38. $group_uuid = uuid_set_uuid('node', 'nid', $group_nid);
  39. }
  40. $node->og_groups[$group_uuid] = $group_uuid;
  41. unset($node->og_groups[$key]);
  42. // Modify og_groups_both as well (gid => title).
  43. $group_title = $node->og_groups_both[$group_nid];
  44. $node->og_groups_both[$group_uuid] = $group_title;
  45. unset($node->og_groups_both[$group_nid]);
  46. }
  47. }
  48. // Support for og_subgroups.
  49. if (!empty($node->og_parent)) {
  50. $group_uuid = uuid_get_uuid('node', 'nid', $node->og_parent->nid);
  51. // Create uuid if it doesn't exists
  52. if (empty($group_uuid)) {
  53. $group_uuid = uuid_set_uuid('node', 'nid', $node->og_parent->nid);
  54. }
  55. $node->og_parent = $group_uuid;
  56. }
  57. }
  58. }
  59. /**
  60. * Go through group UUIDs and put group nids in their place.
  61. */
  62. function node_export_relation_og_set_group_nids(&$nodes) {
  63. foreach ($nodes as &$node) {
  64. if (!empty($node->og_groups)) {
  65. foreach ($node->og_groups as $key => $group_uuid) {
  66. // If this is really a UUID, find the matching nid.
  67. if (uuid_is_valid($group_uuid)) {
  68. $group_nids = entity_get_id_by_uuid(array($group_uuid));
  69. $group_nid = $group_nids[$group_uuid];
  70. $node->og_groups[$group_nid] = $group_nid;
  71. unset($node->og_groups[$key]);
  72. // Modify og_groups_both as well (gid => title).
  73. $group_title = $node->og_groups_both[$group_uuid];
  74. $node->og_groups_both[$group_nid] = $group_title;
  75. unset($node->og_groups_both[$group_uuid]);
  76. }
  77. }
  78. }
  79. // Support for og_subgroups.
  80. if (!empty($node->og_parent) && is_string($node->og_parent)) {
  81. // Create uuid if it doesn't exists
  82. if (uuid_is_valid($node->og_parent)) {
  83. $group_nids = entity_get_id_by_uuid(array($group_uuid));
  84. $node->og_parent = $group_nids[$group_uuid];
  85. }
  86. }
  87. }
  88. }