You are here

function _book_uuid_node_features_pending_sort in UUID Features Integration 7

Sort callback to put parents before children.

1 call to _book_uuid_node_features_pending_sort()
book_uuid_entity_features_rebuild_complete in includes/modules/book.inc
Implements hook_uuid_entity_features_rebuild_complete().

File

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

Code

function _book_uuid_node_features_pending_sort($pending) {
  $pending_by_parent = array();

  // Group by parent.
  foreach ($pending as $uuid => $book) {
    $parent_uuid = $book['parent_uuid'];
    if (empty($pending_by_parent)) {
      $pending_by_parent[$parent_uuid] = array();
    }
    $pending_by_parent[$parent_uuid][$uuid] = $book;
  }
  $sorted_pending = array();

  // Find top-level parents and get all ancestors in order.
  foreach ($pending_by_parent as $parent_uuid => $books) {
    if (empty($pending[$parent_uuid])) {

      // This is a top-level pending - recurse from here.
      $sorted_pending = array_merge($sorted_pending, _book_uuid_node_features_pending_get_ancestors($parent_uuid, $pending_by_parent));
    }
  }
  return $sorted_pending;
}