getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.54k stars 1.41k forks source link

Support relative paths in `getLevelListing` #3110

Open w00fz opened 3 years ago

w00fz commented 3 years ago

Currently getLevelListing only supports absolute paths.

A bad 500 error happens when trying to load a relative path:

error: {type: "Error", message: "Maximum function nesting level of '256' reached, aborting!", code: 0,…}
code: 0
file: "/Users/djamil/Projects/grav/grav-core/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php"
line: 340
message: "Maximum function nesting level of '256' reached, aborting!"
type: "Error"

Firs this error should be more graceful. But also there is nothing stopping us from supporting relative paths. The ajax call for the page picker already sends all the required information. Assuming we are editing /admin/my/page and we are trying to load the route ../other-page in the Page-Picker, this is how it goes:

POST /admin/my/page

data:
__form-name__: flex-pages
form-nonce: <nonce>
__unique_form_id__: <unique_id>
route: ../other-page
field: route
action: getLevelListing
admin-nonce: <admin_nonce>
initial: true
mahagr commented 3 years ago

@w00fz Relative paths work now, except that the selected item is not highlighted because of ../other-page does not match anything. I added a new json variable called route, which contains the normalized version of the selected route.

mahagr commented 3 years ago

We may also want to add support for returning all-relative paths? Or even to select if you want to use relative or absolute path in the modal...?