public function saveWithSection(Page $page, Section $currentParent = null)
    {
        if ($page->hasMainSection()) {
            return $page;
        }

        if (false === $this->_em->contains($page)) {
            $this->_em->persist($page);
        }

        $parent = $page->getSection();
        if (null !== $currentParent && $this->_em->getUnitOfWork()->isScheduledForInsert($currentParent)) {
            $this->_em->detach($currentParent);
        }

        $section = new Section($page->getUid(), ['page' => $page, 'site' => $page->getSite()]);

        $this->getEntityManager()
                ->getRepository('BackBee\NestedNode\Section')
                ->insertNodeAsFirstChildOf($section, $parent);

        return $page->setPosition(0)
                    ->setLevel($section->getLevel());
    }
public function saveWithSection(Page $page, Section $currentParent = null)
    {
        if ($page->hasMainSection()) {
            return $page;
        }

        if (false === $this->_em->contains($page)) {
            $this->_em->persist($page);
        }

        $parent = $page->getSection();
        if (null !== $currentParent && $this->_em->getUnitOfWork()->isScheduledForInsert($currentParent)) {
            $this->_em->detach($currentParent);
        }

        $section = new Section($page->getUid(), ['page' => $page, 'site' => $page->getSite()]);

        $this->getEntityManager()
                ->getRepository('BackBee\NestedNode\Section')
                ->insertNodeAsFirstChildOf($section, $parent);

        return $page->setPosition(0)
                    ->setLevel($section->getLevel());
    }
public function saveWithSection ( Page $ page , Section $ currentParent = null ) { if ( $ page -> hasMainSection ( ) ) { return $ page ; } if ( false === $ this -> _em -> contains ( $ page ) ) { $ this -> _em -> persist ( $ page ) ; } $ parent = $ page -> getSection ( ) ; if ( null !== $ currentParent && $ this -> _em -> getUnitOfWork ( ) -> isScheduledForInsert ( $ currentParent ) ) { $ this -> _em -> detach ( $ currentParent ) ; } $ section = new Section ( $ page -> getUid ( ) , [ 'page' => $ page , 'site' => $ page -> getSite ( ) ] ) ; $ this -> getEntityManager ( ) -> getRepository ( 'BackBee\NestedNode\Section' ) -> insertNodeAsFirstChildOf ( $ section , $ parent ) ; return $ page -> setPosition ( 0 ) -> setLevel ( $ section -> getLevel ( ) ) ; }
Saves a page with a section and returns it.

@param  Page                 $page               The page to be saved with section.
@param  Section|null         $currentParent      Optional, if provided the parent section of the new one.

@return Page                                     The newly page with section.
Saves a page with a section and returns it .