-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Creating custom widget instance validation is weird due to controller type mismatch #27397
Comments
Hi @MellenIO. Thank you for your report.
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
For more details, please, review the Magento Contributor Assistant documentation. @MellenIO do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?
|
Hi @engcom-Echo. Thank you for working on this issue.
|
✅ Confirmed by @engcom-Echo Issue Available: @engcom-Echo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself. |
Hi @MellenIO. Thank you for your report.
The fix will be available with the upcoming 2.4.2 release. |
Summary (*)
See this line of code:
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance/Validate.php#L22
The function
\Magento\Widget\Model\Widget\Instance::validate()
is type hinted to return either a\Magento\Framework\Phrase
or abool
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Widget/Model/Widget/Instance.php#L294
This means the
is_string
check is going to fail. This further means that, unless you type cast the phrase to a string, you will not ever get a constructive error message out of the widget validation controller.This isn't a huge issue for the most part with Magento core because of the frontend validation but for those creating custom widget validation rules it will break.
Examples (*)
Does not output anything.
Proposed solution
I think the easiest solution is just to change the validation controller line to the following:
On Magento sites with custom validation rules we've gotten around this by adding an
afterValidate
plugin to\Magento\Widget\Model\Widget\Instance
which type casts the result to string (and returns a string for subsequent errors, rather than a phrase).The text was updated successfully, but these errors were encountered: