You are here

public function TreeNode::addChild in Ubercart 8.4

Determines if new child is an immediate descendant or not.

This function is completely dependent on the structure of the array returned by taxonomy_get_tree(). Each element in the array knows its depth in the tree and the array is a preorder iteration of the logical tree structure. Therefore, if the parameter is more than one level deeper than $this, it should be passed to the last child of $this.

File

uc_catalog/src/TreeNode.php, line 37

Class

TreeNode
Data structure to mimic Drupal's menu system.

Namespace

Drupal\uc_catalog

Code

public function addChild(&$child) {
  if ($child
    ->getDepth() - $this
    ->getDepth() == 1) {
    $this->children[] = $child;
  }
  else {
    $last_child =& $this->children[count($this->children) - 1];
    $last_child
      ->addChild($child);
  }
}