mplodowski / formbuilder-plugin-public

https://octobercms.com/plugin/renatio-formbuilder
https://octobercms.com/plugin/renatio-formbuilder
2 stars 0 forks source link

Problem with new events (fixed) #45

Closed m49n closed 4 months ago

m49n commented 5 months ago

Describe the bug it is impossible to change an object in an event

Fix was: event('formBuilder.overrideForm', [$this->form]); became event('formBuilder.overrideForm', [&$this->form]);

and Event::listen('formBuilder.overrideForm', function (&$form) with &

same in other events was: event('formBuilder.formSubmitted', [$this->form]); became: event('formBuilder.formSubmitted', [&$this->form]);

Plugin version 4.0.5

Additional context Problem with new events

mplodowski commented 5 months ago

Hi,

please write me what you are trying to do, so I can confirm this.

For example, this code will override form css class property and it is rendered correctly without passing argument by reference:

Event::listen('formBuilder.overrideForm', function ($form) {
    $form->css_class = 'my_class';
});
m49n commented 5 months ago

Hi,

please write me what you are trying to do, so I can confirm this.

For example, this code will override form css class property and it is rendered correctly without passing argument by reference:

Event::listen('formBuilder.overrideForm', function ($form) {
    $form->css_class = 'my_class';
});

Hi, for example I want to override the entire form

Event::listen('formBuilder.overrideForm', function (&$form) {
            if (request()->form) {
                $form = Form::query()
                    ->with([
                        'fields' => fn($query) => $query->isVisible()->with('field_type'),
                    ])
                    ->where('code', request()->form)
                    ->firstOrFail();
            }
        });
m49n commented 4 months ago

Describe the bug it is impossible to change an object in an event

Fix was: event('formBuilder.overrideForm', [$this->form]); became event('formBuilder.overrideForm', [&$this->form]);

and Event::listen('formBuilder.overrideForm', function (&$form) with &

same in other events was: event('formBuilder.formSubmitted', [$this->form]); became: event('formBuilder.formSubmitted', [&$this->form]);

Plugin version 4.0.5

Additional context Problem with new events

@mplodowski Hi, What about this? the reference will not affect the functionality of the event in any way, but it will add the ability to completely redefine the object if necessary.

mplodowski commented 4 months ago

Thanks and sorry for long wait!

Resolved in v4.0.6