skeeks\cms\models\Tree::processAddNode PHP Method

processAddNode() public method

Можно вставлять как уже сохраненную модель с дочерними элементами, так и еще не сохраненную.
public processAddNode ( Tree $target )
$target Tree
    public function processAddNode(Tree $target)
    {
        //Текущая сущьность должна быть уже сохранена, и не равна $target
        if ($this->isNewRecord) {
            throw new Exception('Для начала нужно сохранить');
        }
        if ($this->id == $target->id) {
            throw new Exception('Должны быть разными');
        }
        //Если раздел который мы пытаемся добавить новый, то у него нет детей и он
        if ($target->isNewRecord) {
            $this->processCreateNode($target);
            return $this;
        } else {
            $target->setAttributesForFutureParent($this);
            if (!$target->save(false)) {
                throw new Exception(\Yii::t('skeeks/cms', "Unable to move: ") . Json::encode($target->attributes));
            }
            $this->processNormalize();
        }
        return $this;
    }