Magento 2 – How to Introduce a New Type for Widget Parameter

magento2widget

I am working on an extension which offers custom widgets that include wysiwyg editor and image fields:

<widget id="masonry_category" class="MyCompany\Module\Block\Widget\Category" is_email_compatible="true">
<label translate="true">Masonry: Category</label>
<description translate="true">Category Image with Link</description>
<parameters>
    ...
    <parameter name="featured_image" xsi:type="image" visible="true" required="false">
        <label translate="true">Category Image</label>
    </parameter>
</parameters>

However, as far as I can see, we are not allowed to use these types:

Element 'parameter', attribute
'{http://www.w3.org/2001/XMLSchema-instance}type': The QName value
'image' of the xsi:type attribute does not resolve to a type
definition.

I see some rules for widgets in Magento_Widget:etc/widget.xsd, but I am not sure how would I go about extending this. Unfortunately, the official documentation didn't help me to figure this out.

BTW, one very weird thing about this: I don't see these errors on my local environment (with development mode turned ON + PHP mode for displaying all errors). And my types (editor and image) are working fine. I run into trouble as soon as I deploy the code to our staging environment, which doesn't make sense to me.

Best Answer

Found the solution and wrote a blog post http://mageclass.com/quick-tip-how-to-use-image-wyswyg-or-any-other-non-standard-field-in-magento2-widget/. I am not sure if it's in line with the best practices, the only requirement I had was not to touch the core.

Related Topic