Jump to content

Hooks inheritance


marco
 Share

Recommended Posts

Hi,

I'm currently working on a module that provides controller (as from mvc patterns) functionality for gathering data for page rendering (more to come soon).

And now I'm facing a specific problem:

I created an abstract controller class (lets say AbstractController) that extends WireData. This controller class is ment to be sub classed in ProcessWire projects by the project developers for each template that needs additional data to display.

Now this abstract controller should get a hookable render() method. So I defined public function ___render().

Now if I try to hook in from another plugin via $this->addHookBefore('AbstractController::render', $this, 'doStuff'); nothing happends.

Lets assume I have a HomeController extending AbstractController providin data for the home template.

Now I can hook in via $this->addHookBefore('HomeController::render', $this, 'doStuff'); because HomeController inheritats the ___render() methods from its parent.

The problem is, I don't want to hook into every concrete controller but into their common parent, the AbstractController, instead.

Is there any solution to this problem?

Regards,

Marco

Link to comment
Share on other sites

This has nothing to do with my AbstractController being abstract or not.

The problem is, that the base class provides a hook and is designed to be subclassed. But users can't hook into the method (in this case ___render()) of the base class but would have to hook into every ___render() method of all subclasses which makes this form of abstraction unusable in a ProcessWire context,.

Link to comment
Share on other sites

SOLVED !!!

My class (AbstractController) that provides the hook method (___render()) is located in a namespace (nw\Controllers\AbstractController).

So hooking into this method requires a fully qualified class name:

$this->addHookBefore('nw\Controllers\AbstractController::render', $this, 'doStuff');

  • 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

×
×
  • Create New...