private function copy(Page $page, $title = null, Page $parent = null)
    {
        if (Page::STATE_DELETED & $page->getState()) {
            throw new InvalidArgumentException('Cannot duplicate a deleted page.');
        }

        // Cloning the page
        $new_page = clone $page;
        $new_page->setTitle((null === $title) ? $page->getTitle() : $title)
                ->setLayout($page->getLayout());

        // Setting the clone as first child of the parent
        if (null !== $parent) {
            $new_page = $this->insertNodeAsFirstChildOf($new_page, $parent, $new_page->hasMainSection());
        }

        // Persisting entities
        $this->_em->persist($new_page);

        return $new_page;
    }
private function copy(Page $page, $title = null, Page $parent = null)
    {
        if (Page::STATE_DELETED & $page->getState()) {
            throw new InvalidArgumentException('Cannot duplicate a deleted page.');
        }

        // Cloning the page
        $new_page = clone $page;
        $new_page->setTitle((null === $title) ? $page->getTitle() : $title)
                ->setLayout($page->getLayout());

        // Setting the clone as first child of the parent
        if (null !== $parent) {
            $new_page = $this->insertNodeAsFirstChildOf($new_page, $parent, $new_page->hasMainSection());
        }

        // Persisting entities
        $this->_em->persist($new_page);

        return $new_page;
    }
private function copy ( Page $ page , $ title = null , Page $ parent = null ) { if ( Page :: STATE_DELETED & $ page -> getState ( ) ) { throw new InvalidArgumentException ( 'Cannot duplicate a deleted page.' ) ; } // Cloning the page $ new_page = clone $ page ; $ new_page -> setTitle ( ( null === $ title ) ? $ page -> getTitle ( ) : $ title ) -> setLayout ( $ page -> getLayout ( ) ) ; // Setting the clone as first child of the parent if ( null !== $ parent ) { $ new_page = $ this -> insertNodeAsFirstChildOf ( $ new_page , $ parent , $ new_page -> hasMainSection ( ) ) ; } // Persisting entities $ this -> _em -> persist ( $ new_page ) ; return $ new_page ; }
Copy a page to a new one.

@param  Page                 $page               The page to be copied.
@param  string|null          $title              Optional, the title of the copy, if null (default) the title of the copied page.
@param  Page|null            $parent             Optional, the parent of the copy, if null (default) the parent of the copied page.

@return Page                                     The copy of the page.

@throws InvalidArgumentException                 Raises if the page is deleted.
Copy a page to a new one .