regesh Posted September 4, 2015 Share 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 Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 4, 2015 Share 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 Link to comment Share on other sites More sharing options...
regesh Posted September 4, 2015 Author Share 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 ( Link to comment Share on other sites More sharing options...
regesh Posted September 4, 2015 Author Share Posted September 4, 2015 Get the fields data! = how?? Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 4, 2015 Share 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 } } } Link to comment Share on other sites More sharing options...
regesh Posted September 4, 2015 Author Share 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++; } Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 4, 2015 Share Posted September 4, 2015 The foreach does already give you $item, no need to retrieve it again. Link to comment Share on other sites More sharing options...
regesh Posted September 4, 2015 Author Share Posted September 4, 2015 Thanks. All is works!!! But it's maybe usefull to know for how to get wire('pages') Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 4, 2015 Share Posted September 4, 2015 Exactly like you did mention it: $this->pages or wire('pages'). Link to comment Share on other sites More sharing options...
regesh Posted September 4, 2015 Author Share Posted September 4, 2015 Ok thanks! Link to comment Share on other sites More sharing options...
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