Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert applyFiltersFromModel change #1126

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mjauvin
Copy link
Member

@mjauvin mjauvin commented May 15, 2024

Revert changes to original behavior - too many problems.

Related: #927 #950 #1036 #1099

@LukeTowers
Copy link
Member

@mjauvin was there another issue that popped up? I thought we dealt with all of them now

@mjauvin
Copy link
Member Author

mjauvin commented May 17, 2024

I thought so as well, but this is really hard to pinpoint where the problem comes from. Seems there is always a new case.

That's why I think what we were trying to fix vs what we are breaking is not worth it, makes the Form widget unreliable.

@LukeTowers
Copy link
Member

@mjauvin seems a bit like throwing the baby out with the bathwater. If there's no current issues with the code I don't see why we should revert it.

@mjauvin
Copy link
Member Author

mjauvin commented May 17, 2024

@mjauvin seems a bit like throwing the baby out with the bathwater. If there's no current issues with the code I don't see why we should revert it.

There IS an issue, just didn't create it yet! 😝

@LukeTowers
Copy link
Member

There IS an issue, just didn't create it yet! 😝

Well then let's hear it! 😂

@LukeTowers LukeTowers modified the milestones: 1.2.7, 1.2.8 Jul 22, 2024
@LukeTowers
Copy link
Member

@mjauvin let me know if there's still an issue.

@mjauvin
Copy link
Member Author

mjauvin commented Jul 22, 2024

@LukeTowers yes, this is still an issue. When using filterFields() method or event to show/hide fields for more complex cases, the call to applyFiltersFromModel() in getSaveData() creates problems in create context since the form field values are not set in the filterFields handler (although they are before saving the form when resolving/refreshing field dependencies).

@mjauvin
Copy link
Member Author

mjauvin commented Jul 23, 2024

@LukeTowers I would not release 1.2.7 without reverting this.

@mjauvin
Copy link
Member Author

mjauvin commented Jul 23, 2024

@LukeTowers I am adding a PR to the Winter.Test plugin to demonstrate the issue.

@mjauvin
Copy link
Member Author

mjauvin commented Jul 23, 2024

The bug can be seen when using Winter.Test plugin under the Galleries model by creating/updating an gallery entry and selecting "active" status.

This PR is needed to see the issue: wintercms/wn-test-plugin#20

@mjauvin mjauvin modified the milestones: 1.2.8, 1.2.7 Jul 23, 2024
@mjauvin
Copy link
Member Author

mjauvin commented Jul 23, 2024

This PR resolves the issue: #1170

@mjauvin mjauvin removed this from the 1.2.7 milestone Jul 23, 2024
@mjauvin mjauvin closed this Jul 23, 2024
@LukeTowers LukeTowers deleted the revert-applyFiltersFromModel branch July 23, 2024 20:23
@LukeTowers LukeTowers restored the revert-applyFiltersFromModel branch July 23, 2024 20:23
@LukeTowers LukeTowers deleted the revert-applyFiltersFromModel branch July 23, 2024 20:23
@mjauvin mjauvin restored the revert-applyFiltersFromModel branch July 25, 2024 19:02
@mjauvin mjauvin reopened this Jul 25, 2024
@mjauvin mjauvin added this to the 1.2.7 milestone Jul 25, 2024
@mjauvin
Copy link
Member Author

mjauvin commented Jul 25, 2024

When Backend\Widgets\Form::getSaveData() is called from the FormController (create_onSave() & update_onSave((), the applyFiltersFromModel() call results in a call to the filterFields() method/event handler and its $this->allFields argument is empty.

This is introducing more problems than it ever solved.

@LukeTowers
Copy link
Member

@mjauvin what's the latest on this?

@mjauvin
Copy link
Member Author

mjauvin commented Aug 2, 2024

It's not needed anymore, been replaced

@LukeTowers LukeTowers deleted the revert-applyFiltersFromModel branch August 3, 2024 06:32
@mjauvin mjauvin restored the revert-applyFiltersFromModel branch August 7, 2024 18:03
@mjauvin mjauvin reopened this Aug 7, 2024
@bennothommo
Copy link
Member

@mjauvin would you be able to clarify the state of where we're at with this problem? Your comment last week mentioned this PR was not needed, but now it has been re-opened.

@mjauvin
Copy link
Member Author

mjauvin commented Aug 10, 2024

@mjauvin would you be able to clarify the state of where we're at with this problem? Your comment last week mentioned this PR was not needed, but now it has been re-opened.

Yeah, I just don't know how to fix this anymore. I have tried many different ways, but everytime I eventually find a situation where it breaks.

My best advice for now is to apply this PR to revert the initial changes. The case we were trying to solve in the first place is minor compared to all the other cases where it breaks it.

@bennothommo
Copy link
Member

@mjauvin does the same issues occur when you use the form events / callbacks inside the controller, as opposed to those in the model? I think I've been fairly open with my dislike for the modification of the form within the model, so it'll be interesting to hear the difference.

@mjauvin
Copy link
Member Author

mjauvin commented Aug 10, 2024

@mjauvin does the same issues occur when you use the form events / callbacks inside the controller, as opposed to those in the model? I think I've been fairly open with my dislike for the modification of the form within the model, so it'll be interesting to hear the difference.

What do you mean exactly ?

@bennothommo
Copy link
Member

bennothommo commented Aug 10, 2024

Unless I was mistaken, the original issues were from using the filterFields function in a model (or the model.form.filterFields event) to hide a field. Can you hide a field using the extendFormFields static method of a controller, or use the formExtendFields method in the controller itself?

EDIT: https://wintercms.com/docs/v1.2/docs/backend/forms#extending-form-fields

@mjauvin
Copy link
Member Author

mjauvin commented Aug 10, 2024

@bennothommo you can use those methods, but they wouldn't be triggered by the dependsOn: field config, would they ?

@bennothommo
Copy link
Member

I don't know myself. I tend to avoid this sort of magic and apply the rules to the models themselves through beforeSave callbacks or things of that nature. As I've said in the past, I've never liked the model having an effect on the form because it feels like an anti-pattern for an MVC-based CMS by skipping the controller.

@mjauvin
Copy link
Member Author

mjauvin commented Aug 10, 2024

I don't know myself. I tend to avoid this sort of magic and apply the rules to the models themselves through beforeSave callbacks or things of that nature. As I've said in the past, I've never liked the model having an effect on the form because it feels like an anti-pattern for an MVC-based CMS by skipping the controller.

I guess your forms requirements are not as complex as mine then...

@bennothommo
Copy link
Member

Perhaps, and until someone presents a form configuration so complex as a test case, I'll remain blissfully unaware.

@mjauvin
Copy link
Member Author

mjauvin commented Aug 10, 2024

Perhaps, and until someone presents a form configuration so complex as a test case, I'll remain blissfully unaware.

All I'm saying is we should revert those changes as they break BC.

FYI: I was able to do what I want using events in the controller like this:

    public function relationExtendManageWidget($widget, $field, $model)
    {   
        if ($field != 'tasks') {
            return;
        }
        $widget->bindEvent('form.refreshFields', function ($allFields) use ($widget) {
            $fields = (object)$allFields;
            // manipulate fields here as it it were in filterFields
        });
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants