You are here

function book_uuid_node_features_rebuild_alter in UUID Features Integration 7

Implements hook_uuid_node_features_rebuild_alter().

Replace book parent uuid's with the valid book parameters. As there is no way to guarantee the correct top-down hierarchical order - collect orphan book nodes for post node rebuild processing.

File

includes/modules/book.inc, line 64
uuid_node hooks on behalf of the book module.

Code

function book_uuid_node_features_rebuild_alter($node, $module) {

  // Ensure we don't have a bogus book configuration. book_node_prepare() adds
  // defaults that trigger book_entity_uuid_presave() to create a new book where
  // none is. This just happens when an user with the right permissions reverts
  // the feature.
  if (empty($node->book['bid']) && isset($node->book['original_bid'])) {
    unset($node->book);
  }
  if (isset($node->book)) {
    if (isset($node->book['parent_uuid'])) {
      $parent_node = entity_load_single_by_uuid('node', $node->book['parent_uuid']);
      if ($parent_node && isset($parent_node->book['mlid'])) {

        // Set up node as for add child page.
        $node->book['plid'] = $parent_node->book['mlid'];
        $node->book['menu_name'] = $parent_node->book['menu_name'];
        $node->book['weight'] = $parent_node->book['weight'];
      }
      else {

        // Add to pending.
        _book_uuid_node_features_pending($node);
      }
    }
  }
  $existing = entity_load_single_by_uuid('node', $node->uuid);
  if (!empty($existing->book['mlid'])) {
    $node->book['mlid'] = $existing->book['mlid'];
    $node->book['plid'] = $existing->book['plid'];
  }
  elseif (!empty($existing->book) && !isset($node->book)) {

    // Delete a book that doesn't exist in the export. Abuse the hook_node_delte
    // integration.
    // @TODO is this the right approach?
    book_node_delete($existing);
  }
}