1

I've created a new category text area attribute called featcms. In my custom module category_form.xml I have;

<field name="featcms" template="ui/form/field" sortOrder="13" formElement="wysiwyg">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="wysiwygConfigData" xsi:type="array">
                <item name="settings" xsi:type="array">
                    <item name="theme_advanced_buttons1" xsi:type="string">bold,italic,|,justifyleft,justifycenter,justifyright,|,fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code</item>
                    <item name="theme_advanced_buttons2" xsi:type="boolean">true</item>
                    <item name="theme_advanced_buttons3" xsi:type="boolean">true</item>
                    <item name="theme_advanced_buttons4" xsi:type="boolean">true</item>
                    <item name="theme_advanced_statusbar_location" xsi:type="boolean">true</item>
                </item>
                <item name="files_browser_window_url" xsi:type="boolean">true</item>
                <item name="height" xsi:type="string">100px</item>
                <item name="toggle_button" xsi:type="boolean">true</item>
                <item name="add_variables" xsi:type="boolean">true</item>
                <item name="add_widgets" xsi:type="boolean">true</item>
                <item name="add_images" xsi:type="boolean">true</item>
                <item name="add_directives" xsi:type="boolean">true</item>
            </item>
            <item name="source" xsi:type="string">category</item>
        </item>
    </argument>
    <settings>
        <label translate="true">Featured CMS Small Squares</label>
        <dataScope>featcms</dataScope>
    </settings>
    <formElements>
        <wysiwyg class="Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg">
            <settings>
                <rows>8</rows>
                <wysiwyg>true</wysiwyg>
            </settings>
        </wysiwyg>
    </formElements>
</field>

As you can see I've added 3 buttons - add variables, add widget and add image. The insert variable and insert widget buttons work fine, but when I click the 'insert image...' button, the popup loads and an ajax call is made and succeeds;

[domain/admin]/catalog/category/edit/id/5307/target_element_id/category_form_featcms/?isAjax=true 

But the call responds with json only and nothing renders in the popup - we should be expecting the image upload form here.

I notice when you scrutinise the CMS page 'insert image' button, the ajax url fired is;

[domain/admin]/cms/wysiwyg_images/index/target_element_id/cms_page_form_content/?isAjax=true

So appears to hit a cms/wysiwyg_images specific end point. Do we need to replicate this path for a category attribute? and if so how should this be set in the category_form xml.

Thanks

  • did you find a solution? – Daniel Mar 6 '19 at 13:35
  • I'm struggling with almost the same problem just for the Magento standard attribute description. At vendor/magento/module-catalog/view/adminhtml/ui_component/category_form.xml the item for files_browser_window_url is set to boolean false. So is there any chance to remove that item from that source config? Setting the value to true is not working according to the Daniels answer. – Sebastian May 31 '19 at 14:51
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Jai May 31 '19 at 16:45
2

I was just facing the same problem. The solution lays in the config key files_browser_window_url you pass. You just need to remove

 <item name="files_browser_window_url" xsi:type="boolean">true</item>

and it should work.

In \Magento\Framework\Data\Form\Element\Editor the method _getPluginButtonsHtml() gets called and sets the onclick event value for the "Insert Image" button.

Within this string $this->getConfig('files_browser_window_url') is called and in your case it's "true" so it adds "true" to the url and breaks it with it.

So this field in you xml should work:

<field name="featcms" template="ui/form/field" sortOrder="13" formElement="wysiwyg">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="wysiwygConfigData" xsi:type="array">
                <item name="settings" xsi:type="array">
                    <item name="theme_advanced_buttons1" xsi:type="string">bold,italic,|,justifyleft,justifycenter,justifyright,|,fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code</item>
                    <item name="theme_advanced_buttons2" xsi:type="boolean">true</item>
                    <item name="theme_advanced_buttons3" xsi:type="boolean">true</item>
                    <item name="theme_advanced_buttons4" xsi:type="boolean">true</item>
                    <item name="theme_advanced_statusbar_location" xsi:type="boolean">true</item>
                </item>
                <item name="height" xsi:type="string">100px</item>
                <item name="toggle_button" xsi:type="boolean">true</item>
                <item name="add_variables" xsi:type="boolean">true</item>
                <item name="add_widgets" xsi:type="boolean">true</item>
                <item name="add_images" xsi:type="boolean">true</item>
                <item name="add_directives" xsi:type="boolean">true</item>
            </item>
            <item name="source" xsi:type="string">category</item>
        </item>
    </argument>
    <settings>
        <label translate="true">Featured CMS Small Squares</label>
        <dataScope>featcms</dataScope>
    </settings>
    <formElements>
        <wysiwyg class="Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg">
            <settings>
                <rows>8</rows>
                <wysiwyg>true</wysiwyg>
            </settings>
        </wysiwyg>
    </formElements>
</field>
0

I've found workable variant in Magento_Cms module in cms_page_form ui component:

<field name="custom_field" formElement="wysiwyg">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="source" xsi:type="string">page</item>
        </item>
    </argument>
    <settings>
        <additionalClasses>
            <class name="admin__field-wide">true</class>
        </additionalClasses>
        <label/>
        <dataScope>custom_field</dataScope>
    </settings>
    <formElements>
        <wysiwyg>
            <settings>
                <wysiwyg>true</wysiwyg>
            </settings>
        </wysiwyg>
    </formElements>
</field>
  • Hi, this doesnt work in a category context – pixiemedia Jun 10 '18 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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