uliverse Posted March 13, 2019 Share Posted March 13, 2019 Hi all, does anyone of you know if/how it is possible to add already existing pages to a pageTable field? The only possible way seems to be creating a new pageTable entry... Thanks! Link to comment Share on other sites More sharing options...
dragan Posted March 13, 2019 Share Posted March 13, 2019 Do you mean via API? Check out these forum threads: Link to comment Share on other sites More sharing options...
adrian Posted March 13, 2019 Share Posted March 13, 2019 Here's some code that automatically adds new pages to the page table field: The key part for your needs (I think) is: $pp->{$ptf->name}->add($child); Link to comment Share on other sites More sharing options...
Macrura Posted March 13, 2019 Share Posted March 13, 2019 I had this issue yesterday - client says they added something to a page table, and then it disappeared. In this case we are not adding as children, but have set a parent. My suspicion is that the client had multiple tabs open, and saved the record later on another tab where they didn't have the item added. This then creates the orphaned page. so, same code as adrian posted, i'm using basically to fix these orphans... $p = $pages->get(####); $p->of(false); $p->page_table->add($pages->get(####)); $p->save('page_table'); though i think it will probably be better at some point for me to save the value of the page that created the record into that page table item, and then have a hook that runs and checks for orphans (not children) and adds those to the table. Link to comment Share on other sites More sharing options...
uliverse Posted March 13, 2019 Author Share Posted March 13, 2019 Thanks for the ideas. I need to be able to do that in the backend. But it seems there is no simple way of doing that... Link to comment Share on other sites More sharing options...
adrian Posted March 13, 2019 Share Posted March 13, 2019 1 hour ago, uliverse said: Thanks for the ideas. I need to be able to do that in the backend. But it seems there is no simple way of doing that... The code in that link I posted hooks into the rendering of the page table field in the backend and automatically adds existing child pages. Is that not what you are looking to do? Link to comment Share on other sites More sharing options...
uliverse Posted March 13, 2019 Author Share Posted March 13, 2019 3 minutes ago, adrian said: The code in that link I posted hooks into the rendering of the page table field in the backend and automatically adds existing child pages. Is that not what you are looking to do? Yes and no... it's a bit more complicated I guess... I need to be able to do this manually. If there is no simple solution, I will find a workaround. Thanks for your help, though! Link to comment Share on other sites More sharing options...
adrian Posted March 13, 2019 Share Posted March 13, 2019 Just now, uliverse said: Yes and no... it's a bit more complicated I guess... I need to be able to do this manually. If there is no simple solution, I will find a workaround. Thanks for your help, though! You could make use of http://modules.processwire.com/modules/process-admin-actions/ and build a custom action that lets you choose a Page Table field and then a page to add to that field. Or you could use http://modules.processwire.com/modules/fieldtype-runtime-markup/ and build a page selector field just above or below the Page Table field and on pag save, process the selected page and add it to the PT field. You could also hook into InputfieldPageTable::render and add the page selector interface there. Lots of options really ? 1 Link to comment Share on other sites More sharing options...
uliverse Posted March 13, 2019 Author Share Posted March 13, 2019 1 minute ago, adrian said: You could make use of http://modules.processwire.com/modules/process-admin-actions/ and build a custom action that lets you choose a Page Table field and then a page to add to that field. Or you could use http://modules.processwire.com/modules/fieldtype-runtime-markup/ and build a page selector field just above or below the Page Table field and on pag save, process the selected page and add it to the PT field. You could also hook into InputfieldPageTable::render and add the page selector interface there. Lots of options really ? Hmmm... I will look into those options! Thanks a lot! You are always very helpful. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now