Jump to content
EvanFreyer

Removing PageTable item without deleting page

Recommended Posts

Hi there!

Maybe I am missing something obvious and I could not find anything regarding this in the forums. If this asked before: Sorry!

I can not find an option to remove a page from a PageTable without deleting the actual page. For me, the PageTable module lets me add numerous pages to a parent page, so that I have more control over which items will be displayed and which ones will not. But sometimes I want to switch pages and remove one from the parent page without deleting the child altogether. Is this possible with the default module or does it have to be extended for this purpose?

Cheers

Evan

Share this post


Link to post
Share on other sites

it's a good question - i thought there was (maybe i'm imagining it) some setting where you could tell it what to do with trashed items, e.g. trashed items are deleted, or left there;

ran into a situation yesterday where we wanted to move a child item from one parent to another, but even moving it just allowed it to be on 2 page tables, because the 1st page table remembered the id, and didn't account for the fact that the item was no longer a child of the page table.. ended up being easiest to trash the page and then move it out of the trash to the new parent; but i could see there being a need in future to be able to elegantly move pagetable items around without too much hacking...

  • Like 2

Share this post


Link to post
Share on other sites

I discovered this by chance and wondered why it never got answered. So here it goes: PageTable field is just holding a PageArray. You'd then use $a->remove($key) where $key can be the key or a page object. Then save the page.

// remove page $item from PageTable
$page->pagetablefield->remove($item);
$page->save();
  • Like 5

Share this post


Link to post
Share on other sites

Moving PageTable items between pages still seems to miss an official solution, so I'll bring this up again. Just stumbled into that myself after resorting some items between "categories" (parent page containing the PageTable field).

My solution was rather crude, since I've simply removed the associated rows directly in the database and re-create the PageTable container using the existing "add child" mechanism.

I guess it  shouldn't be too difficult to use the same mechanism to detect orphaned entries (contained in the array but not a child) and offer a similar option to remove them.

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 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 James F Carr
      In the admin, I am trying to access data from a page that contains an inputfieldand autofill that data into the modal edit window for a new entry.
      For instance, I have a template which contains a PageTable field. When I add a new entry to the PageTable, I want to capture the ID from the originating admin page and add it to a field in the edit modal as a way of linking the new entry back to the originating page. The new PageTable entries are NOT children of the originating page, and cannot be for structural reasons. I have attached an image which I hope will help to clarify the basic result I want to achieve.
      Is there a practical means of accomplishing this? I've been able to achieve something similar with the ConnectPageFields module, but it does not work with PageTable fields. Any input would be much appreciated.

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