Prepare move page to new location. Moves also everything that's under the current page.

You need to call $this->save() in order to perform the move.

@param PageInterface $parent New parent page.

@return $this
351499
public function move(PageInterface $parent)
    {
        if (!$this->_original) {
            $clone = clone $this;
            $this->_original = $clone;
        }

        $this->_action = 'move';

        if ($this->route() === $parent->route()) {
            throw new \RuntimeException('Failed: Cannot set page parent to self');
        }
        if (Utils::startsWith($parent->rawRoute(), $this->rawRoute())) {
            throw new \RuntimeException('Failed: Cannot set page parent to a child of current page');
        }

        $this->parent($parent);
        $this->id(time() . md5($this->filePath()));

        if ($parent->path()) {
            $this->path($parent->path() . '/' . $this->folder());
        }

        if ($parent->route()) {
            $this->route($parent->route() . '/' . $this->slug());
        } else {
            $this->route(Grav::instance()['pages']->root()->route() . '/' . $this->slug());
        }

        $this->raw_route = null;

        return $this;
    }
582244
public function bindParent($parent, $parentPropertyName=NULL)
	{
		$this->_parent = $parent;
		$this->_parentPropertyName = $parentPropertyName;
		return $this;
	}
747085
public function setParent(\Fulgurio\LightCMSBundle\Entity\Page $parent = null)
    {
        $this->parent = $parent;

        return $this;
    }
841058
public function moveAction()
	{
		$this->isPostRequest();
		
		$localization = $this->getPageLocalization();

		$page = $localization->getMaster();
		
		$input = $this->getRequestInput();

		$this->lockNestedSet($page);

		try {
			if ($input->has('reference_id')) {
				$sibling = $this->getPageByRequestKey('reference_id');

				if ($sibling === null) {
					throw new CmsException(null, sprintf('Sibling page [%s] not found.', $input->get('reference_id')));
				}

				if ($input->get('reference_type', 'before') === 'after') {
					$page->moveAsNextSiblingOf($sibling);
				} else {
					$page->moveAsPrevSiblingOf($sibling);
				}
				
			} elseif ($input->has('parent_id')) {

				$parent = $this->getPageByRequestKey('parent_id');

				if ($parent === null) {
					throw new CmsException(null, sprintf('Parent page [%s] not found.', $input->get('parent_id')));
				}

				$parent->addChild($page);
			} else {
				throw new \RuntimeException('Move destination is unknown.');
			}

		} catch (DuplicatePagePathException $e) {
			throw new CmsException('sitemap.error.duplicate_path');
		}

		$this->unlockNestedSet($page);

		return new SupraJsonResponse();
	}
658205
public function setAsChildContainerOf(DelegateInterface $parentContainer) : DelegateInterface
    {
        $this->setParentContainer($parentContainer);
        $parentContainer->addChildContainer($this);
        return $this;
    }
518699
public function getParentPage(HasNodeInterface $page, $locale)
    {
        /** @var Node $node */
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->getNodeFor($page);
        $parentNode = $node->getParent();
        $nodeTranslation = $parentNode->getNodeTranslation($locale);
        $parentPage = $nodeTranslation->getRef($this->em);

        return $parentPage;
    }
468763
public function setPosition(BasePage $page)
    {
        if ($page->getParent()) {
            $pageNb = count($page->getParent()->getChildren());
        } else {
            $pageNb = count($this->entityManager->getRepository('VictoirePageBundle:BasePage')->findByParent(null));
        }

        // + 1 because position start at 1, not 0
        $page->setPosition($pageNb + 1);

        return $page;
    }
145594
private function setParent(&$parent)
    {
        if (! is_null($parent)) {
            $this->parent = $parent;

            $this->parent->elements->add($this);
        }

        return $this;
    }
173895
private function buildPageRedirections(PageInterface $page)
    {
        if (!$page->isEnabled()) {
            $redirections = [];

            // Store "from" paths for each locale
            $locales = [];
            /** @var \Ekyna\Bundle\CmsBundle\Model\PageTranslationInterface $translation */
            foreach ($page->getTranslations() as $locale => $translation) {
                $locales[$locale] = $locale;
                $redirections[$locale] = [
                    'from' => $translation->getPath(),
                ];
            }

            // Find the first enabled ancestor
            $parentPage = $page;
            while (null !== $parentPage = $parentPage->getParent()) {
                if ($parentPage->isEnabled()) {
                    // Store "to" paths for each locale
                    foreach ($parentPage->getTranslations() as $locale => $translation) {
                        if (array_key_exists($locale, $redirections)) {
                            $redirections[$locale]['to'] = $translation->getPath();
                            unset($locales[$locale]);
                        }
                        // Check that all locales has been handled
                        if (empty($locales)) {
                            break 2;
                        }
                    }
                }
            }

            if (!empty($redirections)) {
                foreach ($redirections as $locale => $redirection) {
                    if (!(array_key_exists('from', $redirection) && array_key_exists('to', $redirection))) {
                        continue;
                    }
                    // TODO use url generator or i18n routing prefix strategy
                    $localePrefix = $locale != 'fr' ? '/' . $locale : '';
                    $event = new BuildRedirectionEvent($localePrefix . $redirection['from'], $localePrefix . $redirection['to'], true);
                    $this->dispatcher->dispatch(RedirectionEvents::BUILD, $event);
                }
            }
        }
    }
973448
public function moveToTop(ConnectionInterface $con = null)
    {
        if ($this->isFirst()) {
            return $this;
        }

        return $this->moveToRank(1, $con);
    }
139406
public function saveInto(DataObjectInterface $parent)
    {
        $record = $this->record;

        $parent->flushCache(false); // Flush session cache in case a relation id was changed during form->saveInto

        if (!$record) {
            $relName = substr($this->name, -2) == 'ID' ? substr($this->name, -2, 2) : $this->name;

            if ($parent->hasMethod($relName)) {
                $record = $parent->$relName();
            }
        }

        $fields = $this->FieldList(false);
        $form = $this->formFromFieldList($fields, $this->value);

        if ($record) {
            $formDataFields = $form->Fields()->dataFields();

            foreach ($formDataFields as $dataField) {
                if (($dataField instanceof $this) && $dataField !== $this) {
                    $dataField->saveInto($record);
                }
            }

            if (!$this->allowEmpty && !$record->exists() && !count($this->recursiveArrayFilter($form->Data))) {
                return;
            }

            $form->saveInto($record);
            unset($form);

            $record->flushCache(false);

            // Save extra data into field
            if (count($this->extraData)) {
                $record->castedUpdate($this->extraData);
            }

            if (!$record->exists() && count($this->defaultFromParent)) {
                foreach ($this->defaultFromParent as $pField => $rField) {
                    if (is_numeric($pField)) {
                        if ($record->$rField) {
                            continue;
                        }
                        $record->setCastedField($rField, $parent->$rField);
                    } else {
                        if ($record->$pField) {
                            continue;
                        }
                        $record->setCastedField($rField, $parent->$pField);
                    }
                }
            }

            if (count($this->overrideFromParent)) {
                foreach ($this->overrideFromParent as $pField => $rField) {
                    if (is_numeric($pField)) {
                        $record->setCastedField($rField, $parent->$rField);
                    } else {
                        $record->setCastedField($rField, $parent->$pField);
                    }
                }
            }

            $record->write();

            $fieldName = substr($this->name, -2) == 'ID' ? $this->name : $this->name . 'ID';
            $parent->$fieldName = $record->ID;
        } elseif ($parent) {
            $data = $form->Data;
            unset($form);

            if (count($this->extraData)) {
                $data = array_merge($data, $this->extraData);
            }

            $field = $this->name;
            $parent->$field = $data;
        }
    }
151091
public function setPage($page)
  {
    if ($this->isLocked()) {
      return $this->getObj()->setPage($page)->setLocked();
    } else {
      return parent::setPage($page);
    }
  }
287117
public function moveAsLastChildOf(NodeInterface $parentNode)
	{
		$this->validateAddingChildren($parentNode);

		$pos = $parentNode->getRightValue();
		$level = $parentNode->getLevel() + 1;
		$this->move($pos, $level);

		return $this;
	}
628497
public function setParent(BlockInterface $parent = null)
    {
        if (null !== $parent && '' === $this->config->getName()) {
            throw new LogicException('A block with an empty name cannot have a parent block.');
        }

        $this->parent = $parent;

        return $this;
    }
97943
public function move( Page $page, Title $target, array $extraParams = [] ) {
		$this->api->postRequest(
			new SimpleRequest(
				'move', $this->getMoveParams( $page->getId(), $target, $extraParams )
			)
		);

		return true;
	}
1051247
public function copyCellCollection(PHPExcel_Worksheet $parent)
    {
        $this->currentCellIsDirty;
        $this->storeData();

        $this->parent = $parent;
        if (($this->currentObject !== null) && (is_object($this->currentObject))) {
            $this->currentObject->attach($this);
        }
    }
109489
public function moveFirst($parentId = false)
    {
        if ( $this->parentIdField && $parentId === false ) {
            $parentId = $this->owner->{$this->parentIdField};
        }
        $minIdx = $this->getMinIdx($parentId);
        if ( ! $minIdx ) {
            $this->reorder($parentId);
            $minIdx = $this->getMinIdx($parentId);
        }
        if ( $this->parentIdField ) {
            call_user_func("$this->ownerClassName::updateAll", [
                $this->sortField => floor($minIdx / 2),
                $this->parentIdField => $parentId,
            ], [ $this->primaryKey => $this->owner->primaryKey ]);
        } else {
            call_user_func("$this->ownerClassName::updateAll",
                [ $this->sortField => floor($minIdx / 2) ],
                [ $this->primaryKey => $this->owner->primaryKey ]);
        }
        $this->invalidateTagDependency();
    }