regesh Posted September 4, 2015 Posted September 4, 2015 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
LostKobrakai Posted September 4, 2015 Posted September 4, 2015 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
regesh Posted September 4, 2015 Author Posted September 4, 2015 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 (
LostKobrakai Posted September 4, 2015 Posted September 4, 2015 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 } } }
regesh Posted September 4, 2015 Author Posted September 4, 2015 Thanks!!! but this code not works. I think it's because of $this->pages $newSortedPages = $page->itemsList; $i = 0; foreach($newSortedPages as $id){ $item = $this->pages->get($id); $item->sort = $i; $item->save(); $i++; }
LostKobrakai Posted September 4, 2015 Posted September 4, 2015 The foreach does already give you $item, no need to retrieve it again.
regesh Posted September 4, 2015 Author Posted September 4, 2015 Thanks. All is works!!! But it's maybe usefull to know for how to get wire('pages')
LostKobrakai Posted September 4, 2015 Posted September 4, 2015 Exactly like you did mention it: $this->pages or wire('pages').
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now