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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By picarica
      So hello i am trying to get a .png file from file field and put it automatically to image field, why png image is in the file field is because i already have a hook that extracts .zip and uploads all content into file field, but i just realizes i cant use size() function on image in file field so i am tryin got reupload it to images field
      i already have something like  this in ready.php
      $word = ".png"; foreach($page->subor_hry as $file) { if(strpos($file, $word) !== false){ $page->images_thumb = $file->url; } } by my logic it should work but it dosnt i get error ProcessPageEdit: Unable to read: /site-hry/assets/files/1027/flash_fishy_screenshot.png
      when i remove url from $file->url i just get ProcessPageEdit: Item added to ProcessWire\Pageimages is not an allowed type
      so what am i doing wrong? is there some other way to do this ?
      also can i have all this in
      $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { whats the correct function to have it apply on all pages ?
    • By rooofl
      Hi! I am trying to create a hook that takes the value of a form file field, and add it to an image gallery of an existing page.
      $forms->addHookBefore('FormBuilderProcessor::processInputDone', function($e) { $form = $e->arguments(0); if($form->name == 'new-inuse') { // related_font is a page selector $font = $form->getChildByName('related_font'); // getting the page name $fontName = $font->attr('value')->name; // finds the page from its name $fontPage = wire('pages')->find("name=$fontName"); // in_use_image is a file upload field $image = $form->getChildByName('in_use_image'); // trying to add the image to the existing image gallery in_use field $fontPage->in_use->add('$image'); // error here $fontPage->save(); } }); This outputs the following error: `Call to a member function add() on null`. Any idea what’s wrong with my code?
    • By rjgamer
      Hi,
      is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?
      Thanks.
       
    • By rjgamer
      Hi guys,
      the field "redirect_last" of type DateTime got not updated. The update on the field "redirect_counter" works and got saved.
      Does anybody know what I did wrong in my code?
      if ($input->urlSegment(1) === 'redirect') { $page->of(false); $page->redirect_last = time(); $page->redirect_counter += 1; if ($page->save('redirect_counter')) { $session->redirect($page->website_url, 302); } } Thanks.
    • By picarica
      so what i am trying to do is that i uploded some files into file field, and then i want hook to get MD5sum and other stuff from .xml and put it into text field into it coresponding pages, pages like this are gonna be many, for each one i want it to output it into its fields
×
×
  • Create New...