LAPS Posted March 13, 2020 Share Posted March 13, 2020 Hi there, this post would be similar to the one posted in the VIP support relating the FormBuilder module but here is more general. I would like to add a custom method to a namespaced class, say FormBuilderForm. So in my ready.php file I added (and tried) wire('forms')->addHookMethod('FormBuilderForm::myMethodName', function($event) { // $forms->addHookMethod('FormBuilderForm::myMethodName', function($event) { // wire('forms')->addHookMethod('FormBuilderForm::myMethodName', null, function($event) { // $forms->addHookMethod('FormBuilderForm::myMethodName', null, function($event) { // wire()->addHookMethod('FormBuilderForm::myMethodName', function($event) { // $wire->addHookMethod('FormBuilderForm::myMethodName', function($event) { // wire()->addHookMethod('FormBuilderForm::myMethodName', null, function($event) { // $wire->addHookMethod('FormBuilderForm::myMethodName', null, function($event) { // wire('forms')->addHook('FormBuilderForm::myMethodName', function($event) { // $forms->addHook('FormBuilderForm::myMethodName', function($event) { // wire('forms')->addHook('FormBuilderForm::myMethodName', null, function($event) { // $forms->addHook('FormBuilderForm::myMethodName', null, function($event) { // wire()->addHook('FormBuilderForm::myMethodName', function($event) { // $wire->addHook('FormBuilderForm::myMethodName', function($event) { // wire()->addHook('FormBuilderForm::myMethodName', null, function($event) { // $wire->addHook('FormBuilderForm::myMethodName', null, function($event) { // function implementation... }); but by calling the myMethodName method for FormBuilderForm objects e.g. in a template file $form = wire('forms')->get('my_form_name'); $form->myMethodName(); I'm getting the error Fatal Error: Uncaught Error: Call to undefined method ProcessWire\FormBuilderForm::myMethodName() How can I solve the error in order to properly add the method myMethodName to the class FormBuilderForm? Link to comment Share on other sites More sharing options...
teppo Posted March 14, 2020 Share Posted March 14, 2020 The problem here is not about namespaces, but rather that FormBuilderForm doesn't extend Wire (or any class derived from it), which means that it's not hookable. Long story short: currently you can't add methods to FormBuilderForm with hooks — you could submit a request for this to Ryan, but in the short term I'd recommend finding some other way to do whatever it is that you're ultimately trying to achieve with this method ? Link to comment Share on other sites More sharing options...
LAPS Posted March 14, 2020 Author Share Posted March 14, 2020 @teppo Thanks for the clarification. Is there an dedicated place where I can submit a request for this to Ryan? Link to comment Share on other sites More sharing options...
teppo Posted March 14, 2020 Share Posted March 14, 2020 2 minutes ago, LAPS said: Is there an dedicated place where I can submit a request for this to Ryan? I'd say that the FormBuilder support forum is the best way to get his attention. 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