Question

I am created product custom attribute(specification) and which is showing perfect. Now I am looking for add the Show / Hide Editor for my custom field. enter image description here

Any help on this.

Was it helpful?

Solution

For this custom attribute, You should enable wysiwyg editor.

Solution1: from admin

If your attribute product attribute then goto admin>Store>Attribute>Product

Select your attribute goto tab>Storefront Properties>Enable WYSIWYG Make this value to Yes

enter image description here

Solution2 : Using UpgradeData script

If you create this custom attribute using setup script then also using create an updatedata script then using make 'wysiwyg_enabled' => true for attribute.

UpgradeData setup file is:

================

<?php

namespace [VendorName]\[MOduleName]\Setup;

use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;

/**
 * Upgrade Data script
 * @codeCoverageIgnore
 */
class UpgradeData implements UpgradeDataInterface
{
    /**
     * Category setup factory
     *
     * @var CategorySetupFactory
     */
    private $categorySetupFactory;

    /**
     * EAV setup factory
     *
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * Init
     *
     * @param CategorySetupFactory $categorySetupFactory
     * @param EavSetupFactory $eavSetupFactory
     */
    public function __construct(CategorySetupFactory $categorySetupFactory, EavSetupFactory $eavSetupFactory)
    {
        $this->categorySetupFactory = $categorySetupFactory;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    /**
     * {@inheritdoc}
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        /** @var EavSetup $eavSetup */
        $eavSetup= $this->eavSetupFactory->create(['setup' => $setup]);

        $eavSetup->updateAttribute(
            ProductAttributeInterface::ENTITY_TYPE_CODE,
            '[YOUR_ATTRIBUTE_CODE]',
            [
               'wysiwyg_enabled' => true
            ]
        );
         $setup->endSetup();
    }

    /**

}

OTHER TIPS

In case Amit Bera solution doesn't work. Try mine:

Instead of:

    $eavSetup->updateAttribute(
        ProductAttributeInterface::ENTITY_TYPE_CODE,
        '[YOUR_ATTRIBUTE_CODE]',
        [
           'wysiwyg_enabled' => true
        ]
    );

use:

    $eavSetup->updateAttribute(
        ProductAttributeInterface::ENTITY_TYPE_CODE,
        '[YOUR_ATTRIBUTE_CODE]',
        'is_wysiwyg_enabled',
         false
    );
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top