Jump to content
LAPS

addHookMethod for namespaced classes

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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 🙂

Share this post


Link to post
Share on other sites

@teppo Thanks for the clarification.

Is there an dedicated place where I can submit a request for this to Ryan?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...