Jump to content

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?



Link to comment
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
Link to comment
Share on other sites

  • 3 months later...

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
  • Like 5
Link to comment
Share on other sites

  • 3 years later...

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.

Link to comment
Share on other sites

  • 4 years later...

It would be nice to have a simple-to-use solution for this - like the copy/clone/paste options now available for repeaters. My current method is:

  1. In the page tree (using the 'children' tab is best, assuming there is a common parent), copy the page
  2. Delete (trash) the old page
  3. Move the copied page to the new location, edit the title and any other required fields and publish it.
  4. In the Page Table listing for the new parent, add the new child

It would be super to halve the number of steps:

  1. In the old Page Table list, cut/copy the page
  2. In the new Page Table list, paste the page
Link to comment
Share on other sites

OK - a really simple solution if you only concerned about one Page Table Field on the relevant pages. In my case, this is in the context of a module, where the name of the Page Table field is 'motif_block_table'.

In the module's ready():

$this->addHookAfter('Pages::moved', $this, 'afterPagesMoved');


	protected function afterPagesMoved(HookEvent $event) {
		$page = $event->arguments(0);
		$oldParent = $page->parentPrevious;
		$newParent = $page->parent;
		if($oldParent->id == $newParent->id) return;
		if($oldParent->hasField('motif_block_table')) {
			$oldParent->setAndSave('motif_block_table', $oldParent->motif_block_table);
		if($newParent->hasField('motif_block_table')) {
			$newParent->setAndSave('motif_block_table', $newParent->motif_block_table);

So now I have only one operation - namely to move the page in the page tree - and both fields get reset accordingly (although it may be necessary to re-sort the receiving page table as the new child will be added at the end, regardless of where you drag it in the tree). NB this will not work unless your page naming ensures unique names, as there is a risk that the new parent already has a page with the same name as the one you are moving and the move will be forbidden until you rename one of them.

This could easily be generalised to operate outside of a module.

It could also be adapted to refer to an unspecific Page Table field, provided there is only one. If there is more than one Page Table field and you want to track moves, it gets a bit trickier: finding the field to remove the page from is easy enough; then you either need to do something clever in js to select which field it is added to, or else (probably simpler) just go to the page and add the new child to the relevant field.

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

  • Create New...