3

I want to add WYSIWYG enabled textareas as custom fields for categories. I have read all related topics on this site for this issue, but none of the mentioned answers seem to do the trick. Can somebody see what I'm doing wrong?

Note: This is Magento 2.3 - The module works, the attributes are created properly, data is saved correctly, but the WYSIWYG won't show. The configuration setting for WYSIWYG fields is correct too.

/app/code/MyCompant/CategoryFields/Setup/InstallData.php

class InstallData implements InstallDataInterface
{

    private $eavSetupFactory;
    public function __construct(EavSetupFactory $eavSetupFactory)
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $eavSetup->addAttribute(
            Category::ENTITY,
            'sm_category_faq1_content',
            [
                'type' => 'varchar',
                'label' => 'FAQ1 Content',
                'input' => 'textarea',
                'required' => false,
                'sort_order' => 102,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'is_wysiwyg_enabled' => true,
                'is_html_allowed_on_front' => true,
                'global' => ScopedAttributeInterface::SCOPE_STORE,
                'group' => 'General Information',
            ]
        );
    }
}

/app/code/MyCompany/CategoryFields/view/adminhtml/ui_component/category_form.xml

    <fieldset name="custom_content">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Custom Content</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">10</item>
            </item>
        </argument>
        <field name="sm_category_faq1_content">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="class" xsi:type="string">Magento\Catalog\Ui\Component\Category\Form\Element\Wysiwyg</item>
                    <item name="formElement" xsi:type="string">wysiwyg</item>
                    <item name="label" xsi:type="string" translate="true">FAQ1 Content</item>
                    <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">false</item>
                            <item name="theme_advanced_buttons3" xsi:type="boolean">false</item>
                            <item name="theme_advanced_buttons4" xsi:type="boolean">false</item>
                            <item name="theme_advanced_statusbar_location" xsi:type="boolean">false</item>
                        </item>
                        <item name="files_browser_window_url" xsi:type="boolean">false</item>
                        <item name="height" xsi:type="string">250px</item>
                        <item name="toggle_button" xsi:type="boolean">false</item>
                        <item name="add_variables" xsi:type="boolean">false</item>
                        <item name="add_widgets" xsi:type="boolean">false</item>
                        <item name="add_images" xsi:type="boolean">false</item>
                    </item>
                    <item name="template" xsi:type="string">ui/form/field</item>
                    <item name="source" xsi:type="string">category</item>
                    <item name="wysiwyg" xsi:type="boolean">true</item>
                    <item name="dataScope" xsi:type="string">sm_category_faq1_content</item>
                    <item name="sortOrder" xsi:type="number">12</item>
                    <item name="rows" xsi:type="number">8</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>
2
  • Please check your admin configuration Stores->Configuration->General->Content Management->WYSIWYG Options->Enable WYSIWYG Editor Set to "Disabled By Default" or "Enabled By Default". If it is set to "Disabled Completely" you will get only Textarea
    – Rk Rathod
    Sep 10 '19 at 14:24
  • I also checked that already, that's not the issue. Sep 10 '19 at 14:26
2

'is_wysiwyg_enabled' => true, should be 'wysiwyg_enabled' => true

9
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – Jarnail S
    Jan 15 '20 at 12:51
  • 1
    How does it not provide an answer? He has code in which I see the issue. And the issue is that he uses is_wysiwyg_enabled instead of wysiwyg_enabled. There is not much explanation to give. That's just how it is Jan 15 '20 at 13:37
  • I agree! My question was "what am I doing wrong" and this answers it just fine. However, I changed this and reinstalled without any change.. Jan 15 '20 at 14:04
  • Did you also make sure the field was removed from the database? Just reinstalling the module is not sufficient if the field was still in the database. You should remove the module form the setup_modules table to be sure the setup script runs again, and the fields should be remove from eav_attribute table. Using a back-up of the database is often more quick. Also, you could use magerun2, a tool build around bin/magento which has a command line command to remove EAV fields from your database through the CLI. Jan 15 '20 at 14:11
  • 1
    I added some more info to my previous comment :-) Jan 15 '20 at 14:15

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.