public function addChild($class, $id, $label, $permission, $options =[])
    {
        if (is_string($id)) {
            $id = explode('/', $id);
        }

        if (count($id) == 1) {
            if (isset($this->childItems[$id[0]])) {
                return $this->childItems[$id[0]];
            }

            $item = $this->itemBuilder->create(
                $class,
                $id[0],
                $this->getPath() . '/' . $id[0],
                $label,
                $permission,
                $options
            );
            $this->childItems[$id[0]] = $item;
            return $item;
        }

        $parent = array_splice($id, 0, count($id) - 1);
        return $this->getChild($parent)->addChild($class, $id, $label, $permission, $options);
    }
public function addChild($class, $id, $label, $permission, $options =[])
    {
        if (is_string($id)) {
            $id = explode('/', $id);
        }

        if (count($id) == 1) {
            if (isset($this->childItems[$id[0]])) {
                return $this->childItems[$id[0]];
            }

            $item = $this->itemBuilder->create(
                $class,
                $id[0],
                $this->getPath() . '/' . $id[0],
                $label,
                $permission,
                $options
            );
            $this->childItems[$id[0]] = $item;
            return $item;
        }

        $parent = array_splice($id, 0, count($id) - 1);
        return $this->getChild($parent)->addChild($class, $id, $label, $permission, $options);
    }
public function addChild ( $ class , $ id , $ label , $ permission , $ options = [ ] ) { if ( is_string ( $ id ) ) { $ id = explode ( '/' , $ id ) ; } if ( count ( $ id ) == 1 ) { if ( isset ( $ this -> childItems [ $ id [ 0 ] ] ) ) { return $ this -> childItems [ $ id [ 0 ] ] ; } $ item = $ this -> itemBuilder -> create ( $ class , $ id [ 0 ] , $ this -> getPath ( ) . '/' . $ id [ 0 ] , $ label , $ permission , $ options ) ; $ this -> childItems [ $ id [ 0 ] ] = $ item ; return $ item ; } $ parent = array_splice ( $ id , 0 , count ( $ id ) - 1 ) ; return $ this -> getChild ( $ parent ) -> addChild ( $ class , $ id , $ label , $ permission , $ options ) ; }
Add a new child element to the parent node.

@param string $class Class of the item.
@param string $id Id of the item
@param string $label
@param string $permission
@param array $options

@return ItemInterface
Add a new child element to the parent node .