Pete Posted April 11, 2014 Share Posted April 11, 2014 I want to include the page edit form in another module. This can be achieved by doing something like this and the edit form loads perfectly: public function executeEdit() { // Change the breadcrumbs to be something related to our custom module instead of Admin > Pages > etc $this->fuel->breadcrumbs = new Breadcrumbs(); // start with a fresh breadcrumbs list $this->fuel->breadcrumbs->add(new Breadcrumb($this->config->urls->admin . 'myeditpage/', "My Awesome Edit Page")); $processEdit = $this->modules->get('ProcessPageEdit'); return $processEdit->execute(); } However when you save the page it says it has saved but none of the changes are saved. Any ideas what I might need to do to get this working? It's basically for an Intranet system where I don't necessarily want people to have access to the Page tree but want to be able to use the normal PageEdit form to save effort on replicating its functionality unnecessarily. 1 Link to comment Share on other sites More sharing options...
Soma Posted April 11, 2014 Share Posted April 11, 2014 Works perfectly fine for me. 1 Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 Ah, you're right for the majoirty of fields - my issue appears to be with a very specific field I have. I have a select field called "category" with hardware and software as options (these are pages created using a config template) and depending on which one you pick a select field appears for subcategories for either hardware or software. When I edit the page in my custom module, the subcategory field doesn't load any options or show my selected option after save. If I go to edit the same page in the normal way, without saving it, the options are there in the subcategory field and the correct value is selected. Something about using the "custom selector to find selectable pages" option for this subcategory field isn't populating in my custom module. That selector looks like this (not that I think this is the issue): parent=/config/kb-subcategories/, kb_category=page.kb_category 1 Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 Hmm... it is something to do with kb_category=page.kb_category so that narrows it down. When I remove that it's fine. Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 Pete, Have you checked to see if it works from a new admin page with ProcessPageEdit? I have some custom admin pages that use similar custom selectors and they save fine. 1 Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 I'm not setting the custom admin page as ProcessPageEdit though if that's what you mean? Link to comment Share on other sites More sharing options...
Soma Posted April 11, 2014 Share Posted April 11, 2014 The context is missing for the "page", not sure about the detail ATM anymore but you can get around it by adding this wire()->fuel->set("page", $this->pages->get((int) $this->input->get->id)); 3 Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 Right, I see you are getting the ProcessPageEdit module. I was wondering if you create a new page with ProcessPageEdit would things save correctly? Nice one Soma. I bet that's it. Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 Soma's solution works perfectly. I did have a look at the source and see if the page ID was in a field or something since it wasn't pulling it from the URL, but I guess it's something else. Doesn't matter too much as it works now. Thanks guys! Ha, but now my custom admin page isn't correctly highlighted in reno's new admin theme. Guess I can't have everything though hey? Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 I've never tried this way of editing. I usually create a child page called /edit/ for my custom admin page that has the ProcessPageEdit process assigned. Then pass it the the page ID <a href=edit/?id=12345"><?=$page->title;?></a> You can (have everything). I have a lot of custom admin pages that highlight correctly. Give me more detail, perhaps I've already solved it. 2 Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 You know, I hadn't thought of doing it that way Tom - kind of obvious now I understand what you mean Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 It works really well, and keeps the context for everything — including the navigation. Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 Okay, marking Tom's way as the answer. In conjunction with this code in my autoload module I can even have the breadcrumbs displaying correctly: // In init: $this->addHook('ProcessPageEdit::execute', $this, 'articleBreadcrumbs'); public function articleBreadcrumbs($event) { $page = $event->object->getPage(); if ($page->parent == $this->kbHome) { $this->fuel->breadcrumbs = new Breadcrumbs(); // start with a fresh breadcrumbs list $this->fuel->breadcrumbs->add(new Breadcrumb($this->config->urls->admin . 'knowledgebase/', "Knowledgebase")); return $this->fuel->breadcrumbs; } } Since two correct answers were given in this topic I feel a bit bad changing it, but I'm sure Soma won't mind (look at the amount of likes he's had!!). 1 Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 Here are some screenshots of one section of admin pages I have. CFA Today is our news and events site, this is how the editors manage all the news/events/venues Page Tree Navigation I do almost exactly that with breadcrumbs. My breadcrumb module is a little different, but same idea. 2 Link to comment Share on other sites More sharing options...
Soma Posted April 11, 2014 Share Posted April 11, 2014 Of course when setting the edited page in context, it will also get used by other admin code and the current admin page is gone. If you still want to have your own Process you could work around it like $currAdminPage = $this->page; $this->fuel->page = $this->pages->get($this->input->get->id); $editForm = $this->modules->ProcessPageEdit->execute(); $this->fuel->page = $currAdminPage; return $editForm; 3 Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 Quick shot of the news page (filled with test data). Advanced filters are hidden by default. 5 Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 Probably time to get this admin theme out there for general testing. 1 Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 Ha, oh yeah - forgot it was under wraps Of course when setting the edited page in context, it will also get used by other admin code and the current admin page is gone. If you still want to have your own Process you could work around it like $currAdminPage = $this->page; $this->fuel->page = $this->pages->get($this->input->get->id); $editForm = $this->modules->ProcessPageEdit->execute(); $this->fuel->page = $currAdminPage; return $editForm; I feel so silly - that's kind of obvious now you mention it Quick shot of the news page (filled with test data). ... Advanced filters are hidden by default. I'd love to see the code behind that page - it's a bit further developed than mine is but in the same direction I'm heading. Link to comment Share on other sites More sharing options...
Pete Posted April 11, 2014 Author Share Posted April 11, 2014 I've gone back to marking one of Soma's answers as the "solved" answer purely because his way doesn't require the extra pages, though both ways work. For those who are curious, you can use Soma's code in the executeEdit function and this in the executeAdd function to avoid the requirement of extra pages: public function executeAdd() { $addForm = $this->modules->ProcessPageAdd; $addForm->parent_id = your_parent_page_id; return $addForm->execute(); } 1 Link to comment Share on other sites More sharing options...
renobird Posted April 11, 2014 Share Posted April 11, 2014 Makes sense. I might use that method myself instead. In my case, the extra pages were the most obvious method for me, and they were an issue since the news/events editors are jailed to the CFA Today parent. They can't actually see the page tree. I'd love to see the code behind that page - it's a bit further developed than mine is but in the same direction I'm heading. I'll PM you about that. Link to comment Share on other sites More sharing options...
Pete Posted April 14, 2014 Author Share Posted April 14, 2014 So my edit function works great, but my add function fails to override the correct permissions (I'm happy overriding permissions because the users can't see the page tree to cause mayhem and I will have other checks in the code too). I was trying to do something like this: public function executeAdd() { $this->fuel->breadcrumbs = new Breadcrumbs(); // start with a fresh breadcrumbs list $this->fuel->breadcrumbs->add(new Breadcrumb($this->config->urls->admin . 'mymodule/', "My Module")); $this->fuel->page = $this->page; $this->fuel->page->addable = true; $addForm = $this->modules->ProcessPageAdd; $addForm->parent_id = $this->page->id; return $addForm->execute(); } However $this->fuel->page->addable doesn't seem to want to work. I'm probably missing something obvious, but any suggestions? Link to comment Share on other sites More sharing options...
apeisa Posted April 14, 2014 Share Posted April 14, 2014 Add hook after page::addable and event->return true. Link to comment Share on other sites More sharing options...
Pete Posted April 14, 2014 Author Share Posted April 14, 2014 Cheers - I forgot I had similar in place for page edit as well! My next message as about not having template edit access, but I figured I could save a lot of headaches by just allowing the right permissions on the template (though I did see your note on the subject here: https://processwire.com/talk/topic/371-page-specific-permissions/page-2 ). Link to comment Share on other sites More sharing options...
kongondo Posted April 24, 2014 Share Posted April 24, 2014 Reopening this one.... @Pete, I have tried to use the code you posted.... public function executeAdd() { $addForm = $this->modules->ProcessPageAdd; $addForm->parent_id = your_parent_page_id; return $addForm->execute(); } ...to load the PageAdd form within a module. The PageAdd form loads fine but the page does not save - nothing, no errors - but the page values are sent (including template ID). Google hasn't been helpful. I am also having one of those days when I can't see the wood for the trees . What am I failing to add? Ta! Link to comment Share on other sites More sharing options...
renobird Posted April 24, 2014 Share Posted April 24, 2014 Kongondo, I have those days from time-to-time myself. Check Antti's comment above, did you add that hook? I still prefer having pages with core process modules assigned. Perhaps there is some other benefit I'm missing by doing it this way? 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