Magento 2 – How to add WYSIWYG editor in admin configuration options?












1














How to add WYSIWYG editor with textarea in the admin system configuration options?










share|improve this question





























    1














    How to add WYSIWYG editor with textarea in the admin system configuration options?










    share|improve this question



























      1












      1








      1







      How to add WYSIWYG editor with textarea in the admin system configuration options?










      share|improve this question















      How to add WYSIWYG editor with textarea in the admin system configuration options?







      magento2 admin-panel wysiwyg






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Rafael Corrêa Gomes

      4,24222962




      4,24222962










      asked May 9 '18 at 7:01









      Prashant Patel

      822312




      822312






















          2 Answers
          2






          active

          oldest

          votes


















          1















          open your module system.xml from app/code/NameSpace/ModuleName/etc/adminhtml and add following code:




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
          <system>
          <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Custom Label</label>
          <tab>tabname</tab>
          <resource>NameSpace_ModuleNmae::config_modulename</resource>
          <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>General Settings</label>
          <!-- WYSIWYG editor field code start-->
          <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
          <label>WYSIWYG Editor</label>
          <frontend_model>NameSpaceModuleNameBlockAdminhtmlSystemConfigEditor</frontend_model>
          </field>
          <!-- WYSIWYG editor field code end-->
          </group>
          </section>
          </system>
          </config>



          Now create Editor class file Editor.php at app/code/NameSpace/ModuleName/Bloc/Adminhtml/System/Config folder where we create WYSIWYG editor element:




          <?php
          namespace NameSpaceModuleNameBlock;

          use MagentoFrameworkRegistry;
          use MagentoBackendBlockTemplateContext;
          use MagentoCmsModelWysiwygConfig as WysiwygConfig;
          use MagentoFrameworkDataFormElementAbstractElement;

          class Editor extends MagentoConfigBlockSystemConfigFormField
          {
          protected $_coreRegistry;

          public function __construct(
          Context $context,
          WysiwygConfig $wysiwygConfig,
          array $data =
          ) {
          $this->_wysiwygConfig = $wysiwygConfig;
          parent::__construct($context, $data);
          }

          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
          {
          // set wysiwyg for element
          $element->setWysiwyg(true);
          // set configuration values
          $element->setConfig($this->_wysiwygConfig->getConfig($element));
          return parent::_getElementHtml($element);
          }
          }


          Please let me know if you find any problem.






          share|improve this answer





















          • It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
            – Roman Snitko
            May 27 '18 at 11:53



















          1














          Use this code:



          Step 1:



          Create your system.xml under




          app/code/[Name_Space]/[Your_Module]/etc/adminhtml




          <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
          <system>
              <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                  <label>Custom Label</label>
                  <tab>tabname</tab>
                  <resource>[Name_Space]_[Your_Module]::config_[your_module]</resource>
                  <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                      <label>General Settings</label>
                      <!-- WYSIWYG editor field code start-->
                      <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
                          <label>WYSIWYG Editor</label>
                          <frontend_model>[Name_Space][Your_Module]BlockAdminhtmlSystemConfigEditor</frontend_model>
                      </field>
                      <!-- WYSIWYG editor field code end-->
                  </group>
              </section>
          </system>
          </config>


          Step 2:



          Now we create Editor class in file Editor.php under




          app/code/[Name_Space]/[Your_Module]/Block/Adminhtml/System/Config




          folder where we create WYSIWYG editor element



          <?php
          namespace [Name_Space][Your_Module]Block;
          use MagentoFrameworkRegistry;
          use MagentoBackendBlockTemplateContext;
          use MagentoCmsModelWysiwygConfig as WysiwygConfig;
          use MagentoFrameworkDataFormElementAbstractElement;
          class Editor extends MagentoConfigBlockSystemConfigFormField
          {
          /**
          * @var  Registry
          */
          protected $_coreRegistry;
          /**
          * @param Context    $context
          * @param WysiwygConfig $wysiwygConfig
          * @param array      $data
          */
          public function __construct(
              Context $context,
              WysiwygConfig $wysiwygConfig,
              array $data =
          ) {
              $this->_wysiwygConfig = $wysiwygConfig;
              parent::__construct($context, $data);
          }
          protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
          {
              // set wysiwyg for element
              $element->setWysiwyg(true);
              // set configuration values
              $element->setConfig($this->_wysiwygConfig->getConfig($element));
              return parent::_getElementHtml($element);
          }
          }





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f225258%2fmagento-2-how-to-add-wysiwyg-editor-in-admin-configuration-options%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1















            open your module system.xml from app/code/NameSpace/ModuleName/etc/adminhtml and add following code:




            <?xml version="1.0"?>
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
            <system>
            <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Custom Label</label>
            <tab>tabname</tab>
            <resource>NameSpace_ModuleNmae::config_modulename</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>General Settings</label>
            <!-- WYSIWYG editor field code start-->
            <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
            <label>WYSIWYG Editor</label>
            <frontend_model>NameSpaceModuleNameBlockAdminhtmlSystemConfigEditor</frontend_model>
            </field>
            <!-- WYSIWYG editor field code end-->
            </group>
            </section>
            </system>
            </config>



            Now create Editor class file Editor.php at app/code/NameSpace/ModuleName/Bloc/Adminhtml/System/Config folder where we create WYSIWYG editor element:




            <?php
            namespace NameSpaceModuleNameBlock;

            use MagentoFrameworkRegistry;
            use MagentoBackendBlockTemplateContext;
            use MagentoCmsModelWysiwygConfig as WysiwygConfig;
            use MagentoFrameworkDataFormElementAbstractElement;

            class Editor extends MagentoConfigBlockSystemConfigFormField
            {
            protected $_coreRegistry;

            public function __construct(
            Context $context,
            WysiwygConfig $wysiwygConfig,
            array $data =
            ) {
            $this->_wysiwygConfig = $wysiwygConfig;
            parent::__construct($context, $data);
            }

            protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
            {
            // set wysiwyg for element
            $element->setWysiwyg(true);
            // set configuration values
            $element->setConfig($this->_wysiwygConfig->getConfig($element));
            return parent::_getElementHtml($element);
            }
            }


            Please let me know if you find any problem.






            share|improve this answer





















            • It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
              – Roman Snitko
              May 27 '18 at 11:53
















            1















            open your module system.xml from app/code/NameSpace/ModuleName/etc/adminhtml and add following code:




            <?xml version="1.0"?>
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
            <system>
            <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Custom Label</label>
            <tab>tabname</tab>
            <resource>NameSpace_ModuleNmae::config_modulename</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>General Settings</label>
            <!-- WYSIWYG editor field code start-->
            <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
            <label>WYSIWYG Editor</label>
            <frontend_model>NameSpaceModuleNameBlockAdminhtmlSystemConfigEditor</frontend_model>
            </field>
            <!-- WYSIWYG editor field code end-->
            </group>
            </section>
            </system>
            </config>



            Now create Editor class file Editor.php at app/code/NameSpace/ModuleName/Bloc/Adminhtml/System/Config folder where we create WYSIWYG editor element:




            <?php
            namespace NameSpaceModuleNameBlock;

            use MagentoFrameworkRegistry;
            use MagentoBackendBlockTemplateContext;
            use MagentoCmsModelWysiwygConfig as WysiwygConfig;
            use MagentoFrameworkDataFormElementAbstractElement;

            class Editor extends MagentoConfigBlockSystemConfigFormField
            {
            protected $_coreRegistry;

            public function __construct(
            Context $context,
            WysiwygConfig $wysiwygConfig,
            array $data =
            ) {
            $this->_wysiwygConfig = $wysiwygConfig;
            parent::__construct($context, $data);
            }

            protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
            {
            // set wysiwyg for element
            $element->setWysiwyg(true);
            // set configuration values
            $element->setConfig($this->_wysiwygConfig->getConfig($element));
            return parent::_getElementHtml($element);
            }
            }


            Please let me know if you find any problem.






            share|improve this answer





















            • It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
              – Roman Snitko
              May 27 '18 at 11:53














            1












            1








            1







            open your module system.xml from app/code/NameSpace/ModuleName/etc/adminhtml and add following code:




            <?xml version="1.0"?>
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
            <system>
            <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Custom Label</label>
            <tab>tabname</tab>
            <resource>NameSpace_ModuleNmae::config_modulename</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>General Settings</label>
            <!-- WYSIWYG editor field code start-->
            <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
            <label>WYSIWYG Editor</label>
            <frontend_model>NameSpaceModuleNameBlockAdminhtmlSystemConfigEditor</frontend_model>
            </field>
            <!-- WYSIWYG editor field code end-->
            </group>
            </section>
            </system>
            </config>



            Now create Editor class file Editor.php at app/code/NameSpace/ModuleName/Bloc/Adminhtml/System/Config folder where we create WYSIWYG editor element:




            <?php
            namespace NameSpaceModuleNameBlock;

            use MagentoFrameworkRegistry;
            use MagentoBackendBlockTemplateContext;
            use MagentoCmsModelWysiwygConfig as WysiwygConfig;
            use MagentoFrameworkDataFormElementAbstractElement;

            class Editor extends MagentoConfigBlockSystemConfigFormField
            {
            protected $_coreRegistry;

            public function __construct(
            Context $context,
            WysiwygConfig $wysiwygConfig,
            array $data =
            ) {
            $this->_wysiwygConfig = $wysiwygConfig;
            parent::__construct($context, $data);
            }

            protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
            {
            // set wysiwyg for element
            $element->setWysiwyg(true);
            // set configuration values
            $element->setConfig($this->_wysiwygConfig->getConfig($element));
            return parent::_getElementHtml($element);
            }
            }


            Please let me know if you find any problem.






            share|improve this answer













            open your module system.xml from app/code/NameSpace/ModuleName/etc/adminhtml and add following code:




            <?xml version="1.0"?>
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
            <system>
            <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Custom Label</label>
            <tab>tabname</tab>
            <resource>NameSpace_ModuleNmae::config_modulename</resource>
            <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>General Settings</label>
            <!-- WYSIWYG editor field code start-->
            <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
            <label>WYSIWYG Editor</label>
            <frontend_model>NameSpaceModuleNameBlockAdminhtmlSystemConfigEditor</frontend_model>
            </field>
            <!-- WYSIWYG editor field code end-->
            </group>
            </section>
            </system>
            </config>



            Now create Editor class file Editor.php at app/code/NameSpace/ModuleName/Bloc/Adminhtml/System/Config folder where we create WYSIWYG editor element:




            <?php
            namespace NameSpaceModuleNameBlock;

            use MagentoFrameworkRegistry;
            use MagentoBackendBlockTemplateContext;
            use MagentoCmsModelWysiwygConfig as WysiwygConfig;
            use MagentoFrameworkDataFormElementAbstractElement;

            class Editor extends MagentoConfigBlockSystemConfigFormField
            {
            protected $_coreRegistry;

            public function __construct(
            Context $context,
            WysiwygConfig $wysiwygConfig,
            array $data =
            ) {
            $this->_wysiwygConfig = $wysiwygConfig;
            parent::__construct($context, $data);
            }

            protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
            {
            // set wysiwyg for element
            $element->setWysiwyg(true);
            // set configuration values
            $element->setConfig($this->_wysiwygConfig->getConfig($element));
            return parent::_getElementHtml($element);
            }
            }


            Please let me know if you find any problem.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 9 '18 at 7:05









            Mohit Kumar Arora

            6,27841532




            6,27841532












            • It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
              – Roman Snitko
              May 27 '18 at 11:53


















            • It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
              – Roman Snitko
              May 27 '18 at 11:53
















            It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
            – Roman Snitko
            May 27 '18 at 11:53




            It almost works fine. But "Insert Variable" button doesn't work. It throws error: "Uncaught ReferenceError: MagentovariablePlugin is not defined"
            – Roman Snitko
            May 27 '18 at 11:53













            1














            Use this code:



            Step 1:



            Create your system.xml under




            app/code/[Name_Space]/[Your_Module]/etc/adminhtml




            <?xml version="1.0"?>
            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
            <system>
                <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Custom Label</label>
                    <tab>tabname</tab>
                    <resource>[Name_Space]_[Your_Module]::config_[your_module]</resource>
                    <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>General Settings</label>
                        <!-- WYSIWYG editor field code start-->
                        <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
                            <label>WYSIWYG Editor</label>
                            <frontend_model>[Name_Space][Your_Module]BlockAdminhtmlSystemConfigEditor</frontend_model>
                        </field>
                        <!-- WYSIWYG editor field code end-->
                    </group>
                </section>
            </system>
            </config>


            Step 2:



            Now we create Editor class in file Editor.php under




            app/code/[Name_Space]/[Your_Module]/Block/Adminhtml/System/Config




            folder where we create WYSIWYG editor element



            <?php
            namespace [Name_Space][Your_Module]Block;
            use MagentoFrameworkRegistry;
            use MagentoBackendBlockTemplateContext;
            use MagentoCmsModelWysiwygConfig as WysiwygConfig;
            use MagentoFrameworkDataFormElementAbstractElement;
            class Editor extends MagentoConfigBlockSystemConfigFormField
            {
            /**
            * @var  Registry
            */
            protected $_coreRegistry;
            /**
            * @param Context    $context
            * @param WysiwygConfig $wysiwygConfig
            * @param array      $data
            */
            public function __construct(
                Context $context,
                WysiwygConfig $wysiwygConfig,
                array $data =
            ) {
                $this->_wysiwygConfig = $wysiwygConfig;
                parent::__construct($context, $data);
            }
            protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
            {
                // set wysiwyg for element
                $element->setWysiwyg(true);
                // set configuration values
                $element->setConfig($this->_wysiwygConfig->getConfig($element));
                return parent::_getElementHtml($element);
            }
            }





            share|improve this answer




























              1














              Use this code:



              Step 1:



              Create your system.xml under




              app/code/[Name_Space]/[Your_Module]/etc/adminhtml




              <?xml version="1.0"?>
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
              <system>
                  <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                      <label>Custom Label</label>
                      <tab>tabname</tab>
                      <resource>[Name_Space]_[Your_Module]::config_[your_module]</resource>
                      <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                          <label>General Settings</label>
                          <!-- WYSIWYG editor field code start-->
                          <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
                              <label>WYSIWYG Editor</label>
                              <frontend_model>[Name_Space][Your_Module]BlockAdminhtmlSystemConfigEditor</frontend_model>
                          </field>
                          <!-- WYSIWYG editor field code end-->
                      </group>
                  </section>
              </system>
              </config>


              Step 2:



              Now we create Editor class in file Editor.php under




              app/code/[Name_Space]/[Your_Module]/Block/Adminhtml/System/Config




              folder where we create WYSIWYG editor element



              <?php
              namespace [Name_Space][Your_Module]Block;
              use MagentoFrameworkRegistry;
              use MagentoBackendBlockTemplateContext;
              use MagentoCmsModelWysiwygConfig as WysiwygConfig;
              use MagentoFrameworkDataFormElementAbstractElement;
              class Editor extends MagentoConfigBlockSystemConfigFormField
              {
              /**
              * @var  Registry
              */
              protected $_coreRegistry;
              /**
              * @param Context    $context
              * @param WysiwygConfig $wysiwygConfig
              * @param array      $data
              */
              public function __construct(
                  Context $context,
                  WysiwygConfig $wysiwygConfig,
                  array $data =
              ) {
                  $this->_wysiwygConfig = $wysiwygConfig;
                  parent::__construct($context, $data);
              }
              protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
              {
                  // set wysiwyg for element
                  $element->setWysiwyg(true);
                  // set configuration values
                  $element->setConfig($this->_wysiwygConfig->getConfig($element));
                  return parent::_getElementHtml($element);
              }
              }





              share|improve this answer


























                1












                1








                1






                Use this code:



                Step 1:



                Create your system.xml under




                app/code/[Name_Space]/[Your_Module]/etc/adminhtml




                <?xml version="1.0"?>
                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
                <system>
                    <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Custom Label</label>
                        <tab>tabname</tab>
                        <resource>[Name_Space]_[Your_Module]::config_[your_module]</resource>
                        <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                            <label>General Settings</label>
                            <!-- WYSIWYG editor field code start-->
                            <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
                                <label>WYSIWYG Editor</label>
                                <frontend_model>[Name_Space][Your_Module]BlockAdminhtmlSystemConfigEditor</frontend_model>
                            </field>
                            <!-- WYSIWYG editor field code end-->
                        </group>
                    </section>
                </system>
                </config>


                Step 2:



                Now we create Editor class in file Editor.php under




                app/code/[Name_Space]/[Your_Module]/Block/Adminhtml/System/Config




                folder where we create WYSIWYG editor element



                <?php
                namespace [Name_Space][Your_Module]Block;
                use MagentoFrameworkRegistry;
                use MagentoBackendBlockTemplateContext;
                use MagentoCmsModelWysiwygConfig as WysiwygConfig;
                use MagentoFrameworkDataFormElementAbstractElement;
                class Editor extends MagentoConfigBlockSystemConfigFormField
                {
                /**
                * @var  Registry
                */
                protected $_coreRegistry;
                /**
                * @param Context    $context
                * @param WysiwygConfig $wysiwygConfig
                * @param array      $data
                */
                public function __construct(
                    Context $context,
                    WysiwygConfig $wysiwygConfig,
                    array $data =
                ) {
                    $this->_wysiwygConfig = $wysiwygConfig;
                    parent::__construct($context, $data);
                }
                protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
                {
                    // set wysiwyg for element
                    $element->setWysiwyg(true);
                    // set configuration values
                    $element->setConfig($this->_wysiwygConfig->getConfig($element));
                    return parent::_getElementHtml($element);
                }
                }





                share|improve this answer














                Use this code:



                Step 1:



                Create your system.xml under




                app/code/[Name_Space]/[Your_Module]/etc/adminhtml




                <?xml version="1.0"?>
                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../Config/etc/system_file.xsd">
                <system>
                    <section id="yoursectionid" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Custom Label</label>
                        <tab>tabname</tab>
                        <resource>[Name_Space]_[Your_Module]::config_[your_module]</resource>
                        <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                            <label>General Settings</label>
                            <!-- WYSIWYG editor field code start-->
                            <field id="editor_textarea" translate="label comment" sortOrder="1" type="editor" showInStore="1" showInDefault="1" >
                                <label>WYSIWYG Editor</label>
                                <frontend_model>[Name_Space][Your_Module]BlockAdminhtmlSystemConfigEditor</frontend_model>
                            </field>
                            <!-- WYSIWYG editor field code end-->
                        </group>
                    </section>
                </system>
                </config>


                Step 2:



                Now we create Editor class in file Editor.php under




                app/code/[Name_Space]/[Your_Module]/Block/Adminhtml/System/Config




                folder where we create WYSIWYG editor element



                <?php
                namespace [Name_Space][Your_Module]Block;
                use MagentoFrameworkRegistry;
                use MagentoBackendBlockTemplateContext;
                use MagentoCmsModelWysiwygConfig as WysiwygConfig;
                use MagentoFrameworkDataFormElementAbstractElement;
                class Editor extends MagentoConfigBlockSystemConfigFormField
                {
                /**
                * @var  Registry
                */
                protected $_coreRegistry;
                /**
                * @param Context    $context
                * @param WysiwygConfig $wysiwygConfig
                * @param array      $data
                */
                public function __construct(
                    Context $context,
                    WysiwygConfig $wysiwygConfig,
                    array $data =
                ) {
                    $this->_wysiwygConfig = $wysiwygConfig;
                    parent::__construct($context, $data);
                }
                protected function _getElementHtml(MagentoFrameworkDataFormElementAbstractElement $element)
                {
                    // set wysiwyg for element
                    $element->setWysiwyg(true);
                    // set configuration values
                    $element->setConfig($this->_wysiwygConfig->getConfig($element));
                    return parent::_getElementHtml($element);
                }
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 9 '18 at 9:23









                Chirag Patel

                1,973220




                1,973220










                answered May 9 '18 at 7:06









                Chandra Kumar

                251316




                251316






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f225258%2fmagento-2-how-to-add-wysiwyg-editor-in-admin-configuration-options%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    An IMO inspired problem

                    Management

                    Investment