Plugin to allow global re-index / sorting of a set of pages (Pages section adaptation)

Hi,

I would like to create an extension of the Pages section through a panel plugin that would allow to display a specific query of pages and be able to sort them.

The only difference would be to save the new page position to a specific field like “globalIndex” instead of really moving the page using the changeStatus function

Could you help me find a way to do this properly ?

The main idea behind this is to choose the order of all grand children of a specific page even if another order is set within the subpage. Example :

Homepage
    Category 1
         Project 1
         Project 2
         Project 3
   Category 2
         Project A
         Project B
         Project C

On the Homepage I would like to be able to drag and drop all subprojects into this order :

Project C
Project 2
Project A
Project 3
Project B
Project 1

but keep the “native Kirby sort order” in each sub-category.

Thank you !

Maybe @sylvainjule you can tell me the right approach ? Or how I can modify your Pagetable plugin to do so ? Thanks x 1000

It seems like a job for the pages field on the homepage blueprint.

If the user has to be able to add / remove pages from the available pool of projects then you’d just query a collection containing all those different pages for them to pick from.

Or if they should all be automatically added to this field and not one should be missing you’d keep it in sync upon granchildren creation / deletion with a hook that’d append / delete the ids from the field, and hide the select / remove UI from the panel.

Then a toPages() call on this field would give you these pages in a given order without messing with their real position in the folders. And if you need to save a globalIndex key on each page you’d place a hook every time the field is updated on the homepage and get its index with $globalIndex = $page->indexOf($home->fieldname()->toPages());.

Hi @sylvainjule !

Thanks a lot for taking the time to find a solution :slight_smile:
I think indeed this is the best solution in order to keep all of these with native Kirby functions.

:pray: