0

how to create custom attribute description with wysiwyg editor in Category page? like this enter image description here

1
  • please check and update.
    – Msquare
    Nov 2, 2020 at 12:45

3 Answers 3

1

how to get this field in phtml correctly? I have problem, becouse i'm getting output like this:

<?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Output')->categoryAttribute($block->getCurrentCategory(), $block->getCurrentCategory()->getAdditionDesc(), 'addition_desc') ?>

<p>test</p> <p><img src="{{media url="wysiwyg/moutures-uSelect-tailles-321x150.jpg"}}" alt=""></p>

and second:

<?php echo $block->getCurrentCategory()->getAdditionDesc(); ?>

in this one I have html correct but problem is with media, in browser img is like this:

<img src="{{media url="wysiwyg/moutures-uSelect-tailles-321x150.jpg"}}" alt="">
0
<?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();
    }
}
12
  • can you give me full detail ?
    – arun
    Nov 2, 2020 at 10:20
  • I update the answer, create "InstallData.php" in your extension and then put code there and then run upgrade and deploy commands. Nov 2, 2020 at 10:22
  • can you give me category_form.xml file ?
    – arun
    Nov 2, 2020 at 10:28
  • why you want that one? There is not required of that one. Nov 2, 2020 at 10:34
  • for admin inside showing
    – arun
    Nov 2, 2020 at 10:44
0
<?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>
8
  • are you sure that 'input' => 'boolean', is correct?
    – Marius
    Nov 2, 2020 at 10:30
  • i update my answer
    – Msquare
    Nov 2, 2020 at 10:33
  • when i insert a value and save the refresh page attribute value will null
    – arun
    Nov 2, 2020 at 11:09
  • 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, 2020 at 11:49
  • already change but attribute not create in database that's why not insert value, any update ?
    – arun
    Nov 3, 2020 at 5:17

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.