0

I want to update the custom product attribute from textarea to WYSIWYG programmatically. InstallData.php file:

      $eavSetup->addAttribute(
            \Magento\Catalog\Model\Product::ENTITY,
            'Tekglide_video_description',
            [
                'type' => 'text',
                'backend' => '',
                'frontend' => '',
                'label' => 'Video Description',
                'input' => 'textarea',
                'class' => '',
                'source' => '',
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
                'visible' => true,
                'required' => false,
                'user_defined' => false,
                'default' => "",
                'searchable' => false,
                'filterable' => false,
                'comparable' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => true,
                'unique' => false,
                'group' => 'Video',
                'apply_to' => ''
            ]
        );

product_form.xml :

<?xml version="1.0"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="video">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="visible" xsi:type="boolean">true</item>
            </item>
        </argument>
        <container name="container_Tekglide_video_enabled">
            <field name="Tekglide_video_enabled">
                <argument name="data" xsi:type="array">
                    <item name="config" xsi:type="array">
                        <item name="formElement" xsi:type="string">select</item>
                        <item name="dataScope" xsi:type="string">Tekglide_video_enabled</item>
                        <item name="switcherConfig" xsi:type="array">
                            <item name="enabled" xsi:type="boolean">true</item>
                            <item name="rules" xsi:type="array">
                                <item name="0" xsi:type="array">
                                    <item name="value" xsi:type="number">0</item>
                                    <item name="actions" xsi:type="array">
                                        <item name="0" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_title.Tekglide_video_title</item>
                                            <item name="callback" xsi:type="string">hide</item>
                                        </item>
                                        <item name="1" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_embedcode.Tekglide_video_embedcode</item>
                                            <item name="callback" xsi:type="string">hide</item>
                                        </item>
                                        <item name="2" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_link.Tekglide_video_link</item>
                                            <item name="callback" xsi:type="string">hide</item>
                                        </item>
                                        <item name="3" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_label.Tekglide_video_label</item>
                                            <item name="callback" xsi:type="string">hide</item>
                                        </item>
                                        <item name="4" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_description.Tekglide_video_description</item>
                                            <item name="callback" xsi:type="string">hide</item>
                                        </item>
                                    </item>
                                </item>
                                <item name="1" xsi:type="array">
                                    <item name="value" xsi:type="number">1</item>
                                    <item name="actions" xsi:type="array">
                                        <item name="0" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_title.Tekglide_video_title</item>
                                            <item name="callback" xsi:type="string">show</item>
                                        </item>
                                        <item name="1" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_embedcode.Tekglide_video_embedcode</item>
                                            <item name="callback" xsi:type="string">show</item>
                                        </item>
                                        <item name="2" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_link.Tekglide_video_link</item>
                                            <item name="callback" xsi:type="string">show</item>
                                        </item>
                                        <item name="3" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_label.Tekglide_video_label</item>
                                            <item name="callback" xsi:type="string">show</item>
                                        </item>
                                        <item name="4" xsi:type="array">
                                            <item name="target" xsi:type="string">product_form.product_form.video.container_Tekglide_video_description.Tekglide_video_description</item>
                                            <item name="callback" xsi:type="string">show</item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                        <item name="component" xsi:type="string">Tekglide_VideoTab/js/form/element/options</item>
                    </item>
                </argument>
            </field>
        </container>
    </fieldset>
</form>


Any help would be appreciated.

1 Answer 1

0

I figured it out. It was simple. Just needed to create a UpgradeData.php file in my module:


use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class UpgradeData implements UpgradeDataInterface
{
    private $eavSetupFactory;

    public function __construct(EavSetupFactory $eavSetupFactory)
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();

        if ($context->getVersion() && version_compare($context->getVersion(), '1.0.1') < 0) {
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
            
            $eavSetup->updateAttribute(4, 'Tekglide_video_description', 'is_wysiwyg_enabled', 1);
            $eavSetup->updateAttribute(4, 'Tekglide_video_description', 'is_wysiwyg_enabled', 1);
        }
        $setup->endSetup();
    }
}

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.