1

I want to display editor not only textarea so please let me know what can I do here, and how to remove Insert Widget / Insert Variable / Insert Image button there?

<field id="gird_view" translate="label" type="textarea" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
   <label>Grid View Design</label>
</field> 
6

Add this in your system.xml file

<field id="grid_view" translate="label comment" type="editor" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Grid View</label>
    <frontend_model>Vendor\Module\Block\Adminhtml\System\Config\Form\Field\Editor</frontend_model>
</field>

Now create below Block file in your custom module

app/code/Vendor/Module/Block/Adminhtml/System/Config/Form/Field/Editor.php

Content for this file is..

<?php
namespace Vendor\Module\Block\Adminhtml\System\Config\Form\Field;

use Magento\Backend\Block\Template\Context;
use Magento\Cms\Model\Wysiwyg\Config as WysiwygConfig;

class Editor extends \Magento\Config\Block\System\Config\Form\Field
{
    public function __construct(
        Context $context,
        WysiwygConfig $wysiwygConfig,
        array $data = []
    )
    {
        $this->_wysiwygConfig = $wysiwygConfig;
        parent::__construct($context, $data);
    }

    protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
    {
        $element->setWysiwyg(true);
        $element->setConfig($this->_wysiwygConfig->getConfig(array('add_variables' => true, 'add_widgets' => false, 'add_images' => true)));
        return parent::_getElementHtml($element);
    }
}

Create below file in your module

app/code/Vendor/Module/view/adminhtml/layout/adminhtml_system_config_edit.xml

Content for this file is..

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="editor"/>
</page>

Run below command once

php bin/magento cache:clean && php bin/magento cache:flush

Hope this will help you!

  • 1
    Perfect! Its works for me. – sarvesh Dineshkumar Patel Dec 13 '19 at 5:19
  • Hi for an editor it works fine but when I click on Insert Variable then error comes as js "MagentovariablePlugin is not defined". If possible can you tell me this? – sarvesh Dineshkumar Patel Dec 13 '19 at 7:12
  • answer updated please review :) – Kishan Savaliya Dec 13 '19 at 7:16
  • It seems like you just copy answer from commented link and post here. Why you added already posted answer code? – Mehta Prem Dec 13 '19 at 7:20
  • @KishanSavaliya yes it works. now one more, how can remove that button Insert Widget, Insert Variable, Insert widget particular. – sarvesh Dineshkumar Patel Dec 13 '19 at 7:27

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.