Jump to content

Save order after using "page" fieldtype


regesh
 Share

Recommended Posts

I need to save order for elements in global tree after using "page" fieldtype in other page. It's better to look on image attacheted to understand. I wish to know the better and easiest way to solve it or <code> example ! Thanks

post-3359-0-18752900-1441352066_thumb.pn

Link to comment
Share on other sites

May I ask, why you're not simply using the option to rename the "Children" tab to "Item List", where you can sort the children directly without detour?

But You can surely do it like that as well.

Create a hook like this one, but use Pages::saved instead of saveReady: https://processwire-recipes.com/recipes/extending-page-save-process/

Get the fields data and use some of those snippets to save the new sorting: https://processwire.com/talk/topic/3378-move-and-sort-pages-with-the-api/?p=33241

Link to comment
Share on other sites

May I ask, why you're not simply using the option to rename the "Children" tab to "Item List", where you can sort the children directly without detour?

But You can surely do it like that as well.

Create a hook like this one, but use Pages::saved instead of saveReady: https://processwire-recipes.com/recipes/extending-page-save-process/

Get the fields data and use some of those snippets to save the new sorting: https://processwire.com/talk/topic/3378-move-and-sort-pages-with-the-api/?p=33241

Because this field will not use only on parent page.

And i can't find out how to get post values to my fieldtype(page) after page saved (

Link to comment
Share on other sites


public function afterSaveReady($event) {

// Get the soon to be saved page object from the given event

$page = $event->arguments[0];

// Sample condition and changes

if($page->template == "myTemplate" && !$page->isTrash()){

$newSortedPages = $page->itemsList;

foreach($newSortedPages as $sortPage){

// insert snippet to save new sort value

}

}

}

Link to comment
Share on other sites

Thanks!!!

but this code not works. 

I think it's because of $this->pages :-X

 $newSortedPages = $page->itemsList;
             $i = 0;
             foreach($newSortedPages as $id){
               $item = $this->pages->get($id);
               $item->sort = $i;
               $item->save();
               $i++;
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...