Jump to content

Recommended Posts

Posted

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
Posted

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
Posted

Hmm... it is something to do with kb_category=page.kb_category so that narrows it down. When I remove that it's fine.

Posted

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.

  • Like 1
Posted

I'm not setting the custom admin page as ProcessPageEdit though if that's what you mean?

Posted

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
Posted

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.

Posted

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

Posted

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
Posted

You know, I hadn't thought of doing it that way Tom - kind of obvious now I understand what you mean :D

Posted

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
Posted

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
Posted

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
Posted

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.

Posted

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
Posted

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

Posted

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?

  • 2 weeks later...
Posted

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!

Posted

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?

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