Federico Posted March 29, 2018 Share Posted March 29, 2018 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 More sharing options...
elabx Posted March 29, 2018 Share Posted March 29, 2018 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 4 Link to comment Share on other sites More sharing options...
Federico Posted March 29, 2018 Author Share Posted March 29, 2018 @elabx that's great, I've just tested in ready.php and it works as expected. Good hook! I was getting close to this but I didn't know about the possibility to ad executeSomething right in the hook method. Thank you! Link to comment Share on other sites More sharing options...
elabx Posted March 29, 2018 Share Posted March 29, 2018 Check this documentation page, you can also add properties: https://processwire.com/api/hooks/#add_new_method 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