{"record":{"id":"704e2c107da42508","repo":"getgrav/grav","slug":"failed-cannot-set-page-parent-to-self-704e2c","errorCode":null,"errorMessage":"Failed: Cannot set page parent to self","messagePattern":"Failed: Cannot set page parent to self","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"system/src/Grav/Framework/Flex/Pages/Traits/PageLegacyTrait.php","lineNumber":275,"sourceCode":"     */\n    public function file(): ?MarkdownFile\n    {\n        // TODO:\n        throw new RuntimeException(__METHOD__ . '(): Not Implemented');\n    }\n\n    /**\n     * Prepare move page to new location. Moves also everything that's under the current page.\n     *\n     * You need to call $this->save() in order to perform the move.\n     *\n     * @param PageInterface $parent New parent page.\n     * @return $this\n     */\n    public function move(PageInterface $parent)\n    {\n        if ($this->route() === $parent->route()) {\n            throw new RuntimeException('Failed: Cannot set page parent to self');\n        }\n        $rawRoute = $this->rawRoute();\n        if ($rawRoute && Utils::startsWith($parent->rawRoute(), $rawRoute)) {\n            throw new RuntimeException('Failed: Cannot set page parent to a child of current page');\n        }\n\n        $this->storeOriginal();\n\n        // TODO:\n        throw new RuntimeException(__METHOD__ . '(): Not Implemented');\n    }\n\n    /**\n     * Prepare a copy from the page. Copies also everything that's under the current page.\n     *\n     * Returns a new Page object for the copy.\n     * You need to call $this->save() in order to perform the move.\n     *","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Framework/Flex/Pages/Traits/PageLegacyTrait.php#L257-L293","documentation":"FlexPageObject::move() validates the target parent before doing anything; if the new parent's route equals the page's own route (i.e. you are setting the page as its own parent), it throws 'Cannot set page parent to self'. The check compares routes, so aliases or duplicates resolving to the same route also trigger it. It is a self-reference guard, not a storage failure.","triggerScenarios":"Calling $page->move($page); passing a parent object that is actually the same page fetched again (e.g. via a route lookup that resolves back to it); forms that let users pick a parent and default the selection to the current page.","commonSituations":"Admin page-move UIs where the current page appears in the parent dropdown; programmatic tree restructuring with index math that can select the node itself.","solutions":["Guard the call: if ($parent->route() !== $page->route()) { $page->move($parent); }.","In move forms, exclude the page itself (and its descendants) from the selectable parents.","If the goal was only reordering among siblings, use the ordering/metadata API instead of move()."],"exampleFix":"// before\n$page->move($selectedParent);\n\n// after\nif ($selectedParent->route() !== $page->route()) {\n    $page->move($selectedParent);\n}","handlingStrategy":"validation","validationCode":"// Reject a no-op self-move before calling the API\nif ($parent->route() !== $page->route()) {\n    $page->move($parent);\n    $page->save();\n}","typeGuard":null,"tryCatchPattern":"try {\n    $page->move($parent);\n} catch (\\Grav\\Framework\\Flex\\Exception\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'Cannot set page parent to self')) {\n        // treat as no-op: user re-selected the current parent\n        return; // or show a notice\n    }\n    throw $e;\n}","preventionTips":["Exclude the page itself from parent-selection dropdowns in move UIs.","Compare routes before calling move().","Treat same-parent selections as cancel/no-op in form handlers."],"tags":["grav","flex-pages","page-tree","move","self-reference"],"backgroundTag":"circular-reference","analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}