how to create custom attribute description with wysiwyg editor in Category page?
like this
-
please check and update. – Msquare Nov 2 '20 at 12:45
<?php
namespace Vendor\Extension\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Module\Setup\Migration;
use Magento\Catalog\Setup\CategorySetupFactory;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
private $categorySetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory, CategorySetupFactory $categorySetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
$this->categorySetupFactory = $categorySetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
//Category Attribute Create Script
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'attribute_code',
[
'group' => 'General',
'label' => 'Attribute Label',
'type' => 'text',
'input' => 'textarea',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'required' => false,
'sort_order' => 25,
'searchable' => true,
'comparable' => true,
'wysiwyg_enabled' => true,
'is_html_allowed_on_front' => true,
'visible_in_advanced_search' => true
]
);
$setup->endSetup();
}
}
-
-
I update the answer, create "InstallData.php" in your extension and then put code there and then run upgrade and deploy commands. – Dhiren Vasoya Nov 2 '20 at 10:22
-
-
-
<?php
namespace Vendorename\Modulename\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
/* category attribute */
$eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'editor_data');
$eavSetup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY,
'editor_data',
[
'group' => 'General',
'label' => 'Content',
'type' => 'text',
'input' => 'textarea',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'required' => false,
'sort_order' => 25,
'searchable' => true,
'comparable' => true,
'wysiwyg_enabled' => true,
'is_html_allowed_on_front' => true,
'visible_in_advanced_search' => true
]
);
$setup->endSetup();
}
}
app/code/Vendorename/Modulename/view/adminhtml/ui_component
category_form.xml
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="editor_data" sortOrder="10" formElement="wysiwyg" template="ui/form/field">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">editor_data</item>
<item name="wysiwygConfigData" xsi:type="array">
<item name="is_pagebuilder_enabled" xsi:type="boolean">false</item>
<item name="toggle_button" xsi:type="boolean">true</item>
<item name="height" xsi:type="string">150px</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>
</argument>
<settings>
<label translate="true">Add Content</label>
<dataScope>editor_data</dataScope>
</settings>
<formElements>
<wysiwyg>
<settings>
<rows>5</rows>
<wysiwyg>true</wysiwyg>
</settings>
</wysiwyg>
</formElements>
</field>
</fieldset>
</form>
-
-
-
-
plase check my answer i update <item name="source" xsi:type="string">editor_data</item> line in xml file. now data are save and also show into edit mode – Msquare Nov 2 '20 at 11:49
-
already change but attribute not create in database that's why not insert value, any update ? – arun Nov 3 '20 at 5:17