Jump to content
alexcapes

Restoring PageTable page after trashing

Recommended Posts

Hi,

I've noticed when I trash pages from a PageTable field, then restore them, they are restored to their original location, however the connection is broken with the PageTable field.

Is this expected behaviour? Is there a way for it to maintain this relationship? Otherwise restoring it doesn't actually restore it to it's previous state.

Note that in this case the parent pages for the PageTable field is not set as the direct parent.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

not really a solution, but i use the limit page table module to prevent users from trashing items in page tables, and use the extra actions (hide, unpub); so basically the users can't trash pagetable pages – if they don't want those pages anymore then they can unpub;

Share this post


Link to post
Share on other sites
9 hours ago, alexcapes said:

Is this expected behaviour? Is there a way for it to maintain this relationship? Otherwise restoring it doesn't actually restore it to it's previous state.

It would be nice if restoring a page could simultaneously restore relationships for that page, but I'd say the current behaviour is not unexpected. The same limitation would apply if the page had been selected in a Page Reference field (which is PageTable field is like an extended version of).

If you check the names of pages in the Trash you can see how the location and sort position of the original page is stored:

2017-06-08_094236.png.4919b0a0b275399288a3fc0817070549.png

I guess it's just not practical to keep all the relationship information that applied to a page in this kind of format.

Share this post


Link to post
Share on other sites
On 2017-6-7 at 10:45 PM, Robin S said:

It would be nice if restoring a page could simultaneously restore relationships for that page, but I'd say the current behaviour is not unexpected. The same limitation would apply if the page had been selected in a Page Reference field (which is PageTable field is like an extended version of).

If you check the names of pages in the Trash you can see how the location and sort position of the original page is stored:

2017-06-08_094236.png.4919b0a0b275399288a3fc0817070549.png

I guess it's just not practical to keep all the relationship information that applied to a page in this kind of format.

I wonder how difficult it would be to store the relationship info somewhere else and then add the page back to the PageTable if restored? Do you think it's doable with a simple module?

Share this post


Link to post
Share on other sites
13 hours ago, alexcapes said:

Do you think it's doable with a simple module?

It would be possible to get the relationship at the time a page is trashed - for instance, with a PageTable field you could hook InputfieldPageTable::processInput() and get the pages about to be trashed. As for simple it depends on what you're comfortable with. To store the information in a self-contained way your module would need to create and use its own database table. There are existing modules you could look at as an example of how to do this, e.g. Template Access by Parents

  • Like 1

Share this post


Link to post
Share on other sites
On 2017-6-13 at 1:08 AM, Robin S said:

It would be possible to get the relationship at the time a page is trashed - for instance, with a PageTable field you could hook InputfieldPageTable::processInput() and get the pages about to be trashed. As for simple it depends on what you're comfortable with. To store the information in a self-contained way your module would need to create and use its own database table. There are existing modules you could look at as an example of how to do this, e.g. Template Access by Parents

Thanks @Robin S I'll have a play around and see if I can get something working.

Share this post


Link to post
Share on other sites

@alexcapes, are you looking for a solution that would allow non-superusers to restore accidentally trashed PageTable pages? Or is it just an occasional mistake that a superuser needs to fix on request? If it's just the latter you could restore the pages from the trash and use Version Control or Changelog to put the PageTable field back how it was before the deletion.

  • Like 1

Share this post


Link to post
Share on other sites
40 minutes ago, Robin S said:

@alexcapes, are you looking for a solution that would allow non-superusers to restore accidentally trashed PageTable pages? Or is it just an occasional mistake that a superuser needs to fix on request? If it's just the latter you could restore the pages from the trash and use Version Control or Changelog to put the PageTable field back how it was before the deletion.

This would be for super-users only as last resort to fix mistakes.

I think using 'Version Control' may be a workable solution although it does feel a little like using a sledgehammer to crack a nut - I don't really need/want version control and it might add too much complication for the client - and I only need this 'restore' option on one single pagetable field.

Just to note I don't think changelog offers any way to 'restore' the a previous state of a field. 

*Update*
Version Control can be switched on for specific fields only so I think this is going to be a workable solution for me. Thanks @Robin S

*Update #2*
Looks like Version Control is not compatible with PageTable fields.

 

 

Share this post


Link to post
Share on other sites
2 hours ago, alexcapes said:

Just to note I don't think changelog offers any way to 'restore' the a previous state of a field.

For either Version Control or Changelog my thinking was that you would use these just as a way of tracing which pages were deleted from which PageTable fields. You would restore the pages to the PageTable field using the API. The issue with restoring directly from Version Control is that other changes may have been made after the deletion and you wouldn't want to lose those.

But I had a better idea anyway which is just to log any deletions from your PageTable field. Here's an example for a single field but you could extend this by foreaching any fields on the current page of type InputfieldPageTable.

$pages->addHookAfter('saveReady', function(HookEvent $event) {
    $page = $event->arguments(0);
    if(!$page->my_pagetable) return;
    $old_value = $this->pages->getById($page->id, array(
        'getFromCache' => false,
        'getOne' => true,
    ))->my_pagetable;
    $trashed = $old_value->removeItems($page->my_pagetable);
    if(count($trashed)) {
        $trashed_ids = $trashed->implode(', ', 'id');
        $this->log->save('trashed-pt-pages', "Container page: $page->id | Field: my_pagetable | Trashed: $trashed_ids");
    }
});

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Piguanet
      Hola, soy bastante nueva en esto. Tengo en la papelera de mi CMS 4300 aprox. archivos que no puedo borrar. Cuando le doy la opción vaciar me dice que no se puede y continuan ahi.

       
    • By tron1000
      Hello! I use PW 3.0.98 and I have frontend editing enabled for a PageTable Field. Somehow, when I double click the field in the frontend, the iframe in wich the content is displayed is very small (see screenshot). I couldn't find out if thats some CSS conflict or another problem. Any suggestions? Thanks, Andrej
       

    • By Noel Boss
      I use a PageTable field to make edits to children of pages more intuitive…
      To register the hooks, insert the following Snippet inside your init function in your module (or add it to your init.php file):
      /** * Initialize the module. * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. */ public function init() { // Prefill pageTable field $this->wire()->addHookBefore('InputfieldPageTable::render', $this, 'addChildrenToPageTableFieldsHook'); $this->wire()->addHookBefore('InputfieldPageTableAjax::checkAjax', $this, 'addChildrenToPageTableFieldsHook'); } Then, add this hook method:
      /** * Fill pagetable fields with children before editing…. * * @param HookEvent $event */ public function addChildrenToPageTableFieldsHook(HookEvent $event) { $field = $event->object; // on ajax, the first hook has no fieldname if (!$field->name) { return; } // get the edited backend page $editID = $this->wire('input')->get->int('id'); if (!$editID && $this->wire('process') instanceof WirePageEditor) { $editID = $this->wire('process')->getPage()->id; } $page = wire('pages')->get($editID); // disable output formating – without this, the ajax request will not populate the field $page->of(false); // you could also insert a check to only do this with sepcific field names… // $page->set($field->name, $page->children('template=DesiredTemplate')); // just specific templates $page->set($field->name, $page->children); } Now whenever there is a page-table field on your page, it gets populated with the children
    • By pppws
      Hey there,
      i've set up a page wich uses pageTable and it works like a charm.
      for my home page i get several pages. they are sperated in two types:
      a) page has the module 'featured_img'
      b) page doesn't have the 'featured_img'
       
      my pageTable field is called add_modules. so i was wondering if something like 
      <?php foreach ($featured as $child): ?> <?php if ($child->add_modules->module_featuredimg): ?> // show image <?php else: ?> // show text <?php endif; ?> <?php endforeach; ?> is possible?
       
      thanks for your input!
    • By celfred
      Hello,
      I have a feeling I'm missing an easy thing here (again...). If I trash a page from API with :
      mypage->trash()
      Is there a simple way to restore it if needed ? I can do it in back-end, but I'd like to do it through API with something like
      mypage->restore()
       but this doesn't exit  
      So if you can give me a little help on that, I'd appreciate. Thanks in advance !
×
×
  • Create New...