Example #1
0
 /**
  * Custom patch process for Page's sibling or parent node.
  *
  * @param Page  $page
  * @param array $operations passed by reference
  */
 private function patchSiblingAndParentOperation(Page $page, array &$operations)
 {
     $sibling_operation = null;
     $parent_operation = null;
     foreach ($operations as $key => $operation) {
         $op = array('key' => $key, 'op' => $operation);
         if ('/sibling_uid' === $operation['path']) {
             $sibling_operation = $op;
         } elseif ('/parent_uid' === $operation['path']) {
             $parent_operation = $op;
         }
     }
     if (null !== $sibling_operation || null !== $parent_operation) {
         if ($page->isRoot()) {
             throw new BadRequestHttpException('Cannot move root node of a site.');
         }
         if ($page->isOnline(true)) {
             $this->granted('PUBLISH', $page);
             // user must have publish permission on the page
         }
     }
     try {
         if (null !== $sibling_operation) {
             unset($operations[$sibling_operation['key']]);
             $sibling = $this->getPageByUid($sibling_operation['op']['value']);
             $this->granted('EDIT', $sibling->getParent());
             $this->getPageRepository()->moveAsPrevSiblingOf($page, $sibling);
         } elseif (null !== $parent_operation) {
             unset($operations[$parent_operation['key']]);
             $parent = $this->getPageByUid($parent_operation['op']['value']);
             if ($this->isFinal($parent)) {
                 throw new BadRequestHttpException('Can\'t create children of ' . $parent->getLayout()->getLabel() . ' layout');
             }
             $this->moveAsFirstChildOf($page, $parent);
         }
     } catch (InvalidArgumentException $e) {
         throw new BadRequestHttpException('Invalid node move action: ' . $e->getMessage());
     }
 }