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

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By LAPS
      I opened a new wishlist topic on the PW forum for this and in the meantime I ask to the community looking for a reasonable solution.
       
      Using the PageTable field, is there a way to un-restrict the creation of pages under a given parent template page (or as page children if no parent for items is selected)? That is, is there a way to allow the selection of the parent page dynamically / on the fly during page creation via the PageTable field?
    • By LAPS
      I'm using the PW PageTable field extensively and I think an improvement to it could be made regarding the ability to choose the page parent where the page created via PageTable will reside.
      Say you have a PageTable field set like this:
      Edit Field: page_table_field > Details >
      Select one or more templates for items
      > template_one
      > template_two
      > template_three
      Select a parent for items
      > parent_template
      Actually, you can only create pages under the parent_template page (or as page child if no parent for items is selected).
      BTW I am looking for reasons about this limitation.
      What about allowing to choose on the fly where the pages created via PageTable will reside? that is, having the possibility to choose dynamically under which parent page to create the pages?
      Actually, one could overcome to this by creating multiple appropriately set PageTable fields, one PageTable field per PageTable parent for items, but this is unsustainable (?) when you want to create a lot using PageTable…
      By allowing to choose dynamically / on the fly the parent page during page creation via the PageTable field would open up a wider usage of PageTable.
      What do you think about?
       
      @ryan @Robin S
    • By louisstephens
      So I ran into a very strange issue today. I have a template with a pagetable and I went to add an item to it, when I went to select an image (for an image field) the page instantly threw up an error
      "ProcessPageSearchLive: No search specified"
      The page's content also switched to the image attached. This all worked perfectly last week (local mamp box). Has anyone experienced this before, and how did you solve it?
       

    • By louisstephens
      So I went to revisit a project that I put on hold and was met with the following error when trying to trash a page "Operator '&' is not supported for 'status' in ../wire/core/PageFinder.php: 2211
      else if(!$database->isOperator($operator)) { throw new PageFinderSyntaxException("Operator '$operator' is not supported for '$field'."); } I have searched through my templates just to make sure I didn't do anything screwy, but I have no clue why this error is being generated. I can individually delete an item from the trash, but I cant empty the entire trash. 
    • By jploch
      Hey folks,
      I have a question regarding rendering of template files that are in a subfolder of the template folder.
      How would I for example render these PageTable items, when their template files are inside templates/blocks/:
      <div class="grid"> <?php foreach($page->grid_ext as $item): ?> <div id="pteg_<?= $item->id ?>"> <?php echo $item->render(); ?> </div> <?php endforeach; ?> </div> I tried this, but get an error:
      <?php echo $item->render(wire('config')->paths->templates . '/blocks/'); ?>  
×
×
  • Create New...