Jump to content

Page Edit in another module


Pete
 Share

Recommended Posts

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.

  • Like 1
Link to comment
Share on other sites

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

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

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? :D

Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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!!).

  • Like 1
Link to comment
Share on other sites

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

post-474-0-04795700-1397222418_thumb.png

Navigation

post-474-0-93027600-1397222582_thumb.png

I do almost exactly that with breadcrumbs. My breadcrumb module is a little different, but same idea.

:)

  • Like 2
Link to comment
Share on other sites

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

Ha, oh yeah - forgot it was under wraps :D


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

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();
}
  • Like 1
Link to comment
Share on other sites

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. :D

Link to comment
Share on other sites

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

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

  • 2 weeks later...

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 :unsure: . What am I failing to add? Ta!

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...