Jump to content

virtual url function within ready.php - possible?


Federico
 Share

Recommended Posts

Hi there, 

adding a function in ready.php (like I normally do in custom module) throws an error, for obvious reasons. How can I implement a hookable url within the ready.php (admin side)?

for instance, if I hook a pageLister execution to add a button to it like this:

$wire->addHookAfter("ProcessPageLister::execute", function($event) {
    if(wire('page')->id === 1413) { // the particular Lister instance page id
        $out = $event->return;
        $out .= '';
        $btn = wire('modules')->get("InputfieldButton");
        $btn->attr('data-href', "./addNewRecordal");
        $btn->addClass("pw-modal");
        if(!$this->config->ajax) $out .= $btn->render();
        $event->return = $out;
    }   
}

How can actually create a virtual url for that button? in a custom module it can be achieved like this:

public function ___executeAddNewRecordal() {
    //
    // Create new page and redirect to its edit section
    $p = new Page();
    $p->template = '02_template';
    $p->parent_id = 1040;
    $p->name = 'recordal_' . $pageRecordalsMicrotime;
    $p->title = 'Recordal_' . $pageRecordalsMicrotime;
    $p->created_users_id = $this->user->id;
    $p->of(false);
    $p->save();

    $this->session->redirect(wire('config')->urls->admin."page/edit/?id={$p->id}&modal=1");

}

..but in ready.php this is not possible. The tricky thing is that I have to hook a modal, I think, and this is not achievable via PHP afaik. Any hint? thanks

Link to comment
Share on other sites

Here the url should be add-new-recordal, so it gets read by the process module:

$wire->addHookAfter("ProcessPageLister::execute", function($event) {
    if(wire('page')->id === 1413) { // the particular Lister instance page id
        $out = $event->return;
        $out .= '';
        $btn = wire('modules')->get("InputfieldButton");
        $btn->attr('data-href', "./add-new-recordal/");
        $btn->addClass("pw-modal");
        if(!$this->config->ajax) $out .= $btn->render();
        $event->return = $out;
    }   
}

I have done this in init.php but my wild guess is it should work on ready.php too: 

$wire->addHook("ProcessPageLister::executeAddNewRecordal", function($event) {
     //
    // Create new page and redirect to its edit section
    $p = new Page();
    $p->template = '02_template';
    $p->parent_id = 1040;
    $p->name = 'recordal_' . $pageRecordalsMicrotime;
    $p->title = 'Recordal_' . $pageRecordalsMicrotime;
    $p->created_users_id = $this->user->id;
    $p->of(false);
    $p->save();

    $this->session->redirect(wire('config')->urls->admin."page/edit/?id={$p->id}&modal=1");
}

From what I can see, the creation of the page and redirect is already performed in an iframe modal, so it will all happen in the iframe opened with the button you are rendering. Or maybe I'm missing a point here :)

  • Like 4
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...