Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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 (

Posted

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

}

}

}

Posted

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++;
}

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
×
×
  • Create New...