Description
Summary (*)
See this line of code:
The function \Magento\Widget\Model\Widget\Instance::validate()
is type hinted to return either a \Magento\Framework\Phrase
or a bool
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 (*)
$firstResult = __('Test message');
if ($firstResult !== true && is_string($firstResult)) {
echo 'We have an error!';
}
Does not output anything.
Proposed solution
I think the easiest solution is just to change the validation controller line to the following:
if ($result !== true && (is_string($result) || ($result instanceof \Magento\Framework\Phrase)) {
// ...
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).
Metadata
Metadata
Assignees
Labels
Type
Projects
Status