Pete Posted May 28, 2015 Share Posted May 28, 2015 Hi guys I want to hook and replace the output of InputfieldFile's renderItem function as I want to change the output in a module but only for one template (narrowing down the template is the easy part). The idea is I don't want to have a whole new module just for changing the output on one template in the admin. My problem is that I need the same 3 arguments the original funciton has and I'm just not sure how to go about it: protected function ___renderItem($pagefile, $id, $n) { Any ideas? I got as far as this: $this->addHookBefore("InputfieldFile::renderItem", $this, "renderFile"); and in my renderFile function I did this: public function renderField(HookEvent $event) { $inputfield = $event->object; if($this->page->template != 'admin' || !$inputfield instanceof InputfieldFile || $this->input->urlSegment1 != 'attach') return; // 'attach' is the urlsegment I'm looking out for in my ProcessModule as it's that particular page on the module I want to alter the file field's markup for ... } But then I don't know how to get $id and $n from the original function... any ideas? Link to comment Share on other sites More sharing options...
horst Posted May 29, 2015 Share Posted May 29, 2015 It works as always with params: $inputfield = $event->object; $pagefile = $event->arguments(0); $id = $event->arguments(1); $n = $event->arguments(2); 1 Link to comment Share on other sites More sharing options...
Soma Posted May 29, 2015 Share Posted May 29, 2015 Or better named $pagefile = $event->arguments("pagefile"); $id = $event->arguments("id"); $n = $event->arguments("n"); 2 Link to comment Share on other sites More sharing options...
horst Posted May 29, 2015 Share Posted May 29, 2015 Or better named I'm a lazy writer. But you are right, named is more future save. Link to comment Share on other sites More sharing options...
Pete Posted May 29, 2015 Author Share Posted May 29, 2015 Thanks guys, seems really obvious now Link to comment Share on other sites More sharing options...
Soma Posted May 29, 2015 Share Posted May 29, 2015 Yeah it's one of the few things I remember without thinking. Link to comment Share on other sites More sharing options...
Pete Posted May 30, 2015 Author Share Posted May 30, 2015 I certainly won't be forgetting it in a hurry Just a quick one - is there any way/need to ever display the object equivalent of array_keys? Usually ends in recursion on objects in ProcessWire, but I can never remember when $page is $event->object or $event->arguments[0] etc etc. Is there an idiot's guide list to which one is available depending on where you're hooking? I mean basically the stuff like the $page object that isn't necessarily as obvious as a parameter as to how to access that data. Link to comment Share on other sites More sharing options...
Soma Posted May 30, 2015 Share Posted May 30, 2015 If you look at the hooking method and you see the arguments it is always clearer. If theres a $page you need to use arguments. But in cases if you hook the class Page you get the page with $event->object. 1 Link to comment Share on other sites More sharing options...
Pete Posted May 31, 2015 Author Share Posted May 31, 2015 I'm with you now - thanks Soma. Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 31, 2015 Share Posted May 31, 2015 Also quite useful: When hooking ProcessPageEdit the edited page is $event->object->getPage(); 1 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