Jump to content

Hooking InputfieldFile::renderItem


Pete
 Share

Recommended Posts

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

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

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.

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