5

So far, in all the documentation and tutorials for UI Components that I've come across (Like the documentation here: https://devdocs.magento.com/guides/v2.3/ui_comp_guide/bk-ui_comps.html, or in this sample module: https://github.com/magento/magento2-samples/tree/master/sample-module-form-uicomponent), you can only create UI Components as a separate page/route in the backend.

I want to create a UI Component that functions as a parameter in a widget. Is there a way to do this? Specifically, I want to do something along these lines:

In widget.xml:

<widget class="MyWidgetClass">
    <label>My Widget</label>
        <parameters>
            <parameter name="product" xsi:type="SOME_UI_COMPONENT">
        </parameters>
    </label>
</widget>

Is there a way to make something like this happen? If I do create a UI component as a parameter, how do I get the parameter values to save in the widget?

1 Answer 1

1

You can use this Magento 2 module. https://github.com/graschik/magento-2-admin-ui/blob/HEAD/docs/widgets/using-ui-components/README.md

Example:

<?xml version="1.0" encoding="UTF-8"?>
<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
    <widget id="example_widget_with_ui_components"
            class="Grasch\AdminUi\Block\Widget\ExampleOfUIComponents">
        <label translate="true">Example Of Widget With Ui Components</label>
        <description translate="true">Example Of Widget With Ui Components</description>
        <parameters>
            <parameter name="component_data" xsi:type="block">
                <block class="Grasch\AdminUi\Block\Adminhtml\Widget\Ui\Components">
                    <data>
                        <item name="namespace" xsi:type="string">widget_example_form</item>
                    </data>
                </block>
            </parameter>
        </parameters>
    </widget>
</widgets>
1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Jan 18, 2023 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.