You are here

protected function TreeRebuilder::buildThread in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 src/Storage/TreeRebuilder.php \Drupal\entity_hierarchy\Storage\TreeRebuilder::buildThread()

Build thread for a given item ID and parent.

Parameters

array $weights: Existing thread weights.

array $items: All items.

int $id: Item ID.

int $parent: Parent ID.

array $flipped_sets: Items grouped by parent ID, ordered by weight.

1 call to TreeRebuilder::buildThread()
TreeRebuilder::treeSort in src/Storage/TreeRebuilder.php
Sorts tree.

File

src/Storage/TreeRebuilder.php, line 241

Class

TreeRebuilder
Defines a class for rebuilding the tree.

Namespace

Drupal\entity_hierarchy\Storage

Code

protected function buildThread(array &$weights, array $items, $id, $parent, array $flipped_sets) {
  $flipped = $flipped_sets[$parent];
  $weights[$id] = [
    $flipped[$id],
  ];
  if (isset($items[$parent])) {
    $next_parent = $items[$parent];
    $flipped = $flipped_sets[$next_parent];
    $weights[$parent] = [
      $flipped[$parent],
    ];
    if (!isset($weights[$next_parent]) && isset($items[$next_parent])) {
      $this
        ->buildThread($weights, $items, $next_parent, $items[$next_parent], $flipped_sets);
    }
    if (isset($weights[$next_parent])) {
      $weights[$parent] = array_merge($weights[$next_parent], $weights[$parent]);
    }
    $weights[$id] = array_merge($weights[$parent], $weights[$id]);
  }
}