Pimcore\Model\Element\Service::updateChilds PHP Method

updateChilds() protected method

protected updateChilds ( Pimcore\Model\Element\ElementInterface $target, Pimcore\Model\Element\ElementInterface $new ) : void
$target Pimcore\Model\Element\ElementInterface the parent element
$new Pimcore\Model\Element\ElementInterface the newly inserted child
return void
    protected function updateChilds($target, $new)
    {
        if (is_array($target->getChilds())) {
            //check in case of recursion
            $found = false;
            foreach ($target->getChilds() as $child) {
                if ($child->getId() == $new->getId()) {
                    $found = true;
                }
            }
            if (!$found) {
                $target->setChilds(array_merge($target->getChilds(), [$new]));
            }
        } else {
            $target->setChilds([$new]);
        }
    }