Example #1
0
 /**
  * Creating sorted array of nodes
  *
  * @param array $children
  * @param string $path
  * @param \Magento\Framework\DataObject $parent
  * @return void
  */
 public function addChildNodes($children, $path, $parent)
 {
     if (isset($children[$path])) {
         foreach ($children[$path] as $child) {
             $childrenNodes = $parent->getChildrenNodes();
             if ($childrenNodes && isset($childrenNodes[$child->getId()])) {
                 $childrenNodes[$child['entity_id']]->setChildrenNodes([$child->getId() => $child]);
             } else {
                 if ($childrenNodes) {
                     $childrenNodes[$child->getId()] = $child;
                 } else {
                     $childrenNodes = [$child->getId() => $child];
                 }
                 $parent->setChildrenNodes($childrenNodes);
             }
             if ($path) {
                 $childrenPath = explode('/', $path);
             } else {
                 $childrenPath = [];
             }
             $childrenPath[] = $child->getId();
             $childrenPath = implode('/', $childrenPath);
             $this->addChildNodes($children, $childrenPath, $child);
         }
     }
 }