public function cloneAction(Page $source, Page $parent = null, $sibling = null, Request $request)
    {
        // user must have view permission on chosen layout
        $this->granted('VIEW', $source->getLayout());

        if (null !== $sibling) {
            $parent = $sibling->getParent();
        } elseif (null === $parent) {
            $parent = $source->getParent();
        }

        if (null !== $parent) {
            $this->granted('EDIT', $parent);
        } else {
            $this->granted('EDIT', $this->getApplication()->getSite());
        }

        $page = $this->getPageRepository()->duplicate(
            $source,
            $request->request->get('title'),
            $parent,
            true,
            $this->getApplication()->getBBUserToken()
        );

        $this->getApplication()->getEntityManager()->persist($page);
        $this->getApplication()->getEntityManager()->flush();

        if (null !== $sibling) {
            $this->getPageRepository()->moveAsPrevSiblingOf($page, $sibling);
        }

        return $this->createJsonResponse(null, 201, [
            'Location' => $this->getApplication()->getRouting()->getUrlByRouteName(
                'bb.rest.page.get',
                [
                    'version' => $request->attributes->get('version'),
                    'uid'     => $page->getUid(),
                ],
                '',
                false
            ),
            'BB-PAGE-URL' => $page->getUrl()
        ]);
    }