pwFoo Posted April 1, 2015 Posted April 1, 2015 Is it possible to add a method to the current $field via addHook()? I try to add dynamic functions to fields, but each field will have a custom dynamic function.
LostKobrakai Posted April 1, 2015 Posted April 1, 2015 I don't know what exactly you mean by "current" but you can add methods to each class: http://processwire.com/api/hooks/#add_new_method Maybe you can just use a parameter to determine what should be executed. Edit: Thinking a little more about this. What about this. function myHookFunction($event){ if($event->object->name !== "YOUR_FIELD") return; } 1
pwFoo Posted April 1, 2015 Author Posted April 1, 2015 Hi, your way should work fine, but I tried to reduce the overhead. The dynamic function should be added to the current form field object ("$myField", any Inputfield) instead of each instance of a class ("myClass::method"). If there isn't a way I'll do it like you suggested it above.
Wanze Posted April 1, 2015 Posted April 1, 2015 Hi pwFoo, Check the section "Do I want my hook to apply to all instances of a class, or just one?" here https://processwire.com/api/hooks/ It's possible to attach hooks to "single" objects. 2
pwFoo Posted April 1, 2015 Author Posted April 1, 2015 Sorry... haven't seen it... Thanks!!! I'll try it. *UPDATE* Works fine!
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