2
protected function _prepareLayout()
        {
            $return = parent::_prepareLayout();
            if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
                $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
            }
            return $return;
        }

I have a custom module with an admin grid. I try to use TinyMCE but it gives an error in console as described in this title. I use the following code

$fieldset->addField("preface", "editor", array(
                        "label" => Mage::helper("knowledgebase")->__("Preface"),
                        'style' => 'width:98%; height:300px;',
                        'wysiwyg' => true,
                        'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
                        "name" => "preface",
                        ));

protected function _prepareLayout()
        {
            $return = parent::_prepareLayout();
            if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
                $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
            }
            return $return;
        }

2 Answers 2

6

You are probably missing the JS files required for the editor. Check out this blogpost about integrating the editor on custom admin forms.

Especially the first part:

Add necessary js and css files in app/design/frontend/default/default/layout/editor.xml

<default>
            <reference name="head">
            <action method="setCanLoadExtJs"><flag>1</flag></action>
            <action method="setCanLoadTinyMce"><flag>1</flag></action>
            <action method="addJs"><script>mage/adminhtml/variables.js</script></action>
            <action method="addJs"><script>mage/adminhtml/wysiwyg/widget.js</script></action>
            <action method="addJs"><script>lib/flex.js</script></action>
            <action method="addJs"><script>lib/FABridge.js</script></action>
            <action method="addJs"><script>mage/adminhtml/flexuploader.js</script></action>
            <action method="addJs"><script>mage/adminhtml/browser.js</script></action>
            <action method="addJs"><script>prototype/window.js</script></action>
            <action method="addJs"><script>prototype/prototype.js</script></action>
            <action method="addItem"><type>js_css</type><name>prototype/windows/themes/default.css</name></action>
            <action method="addItem"><type>js_css</type><name>prototype/windows/themes/magento.css</name></action>
            </reference>
    </default>
1
  • Thank you, this solved my issue. I put your code in app\design\adminhtml\default\default\layout\my-module.xml Commented Sep 27, 2016 at 12:56
0

You can also utilize the pre-made handle for the wysiwyg editor.

If the editor javascript is only necessary for the admin module you are creating as well as the ones that already use it then you can create an xml document (titled anything with the extension xml) in app/design/adminhtml/default/default/layout/editor.xml and add the following xml.

<your_modules_handle_here>
     <update handle="editor" />
</your_modules_handle_here>

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.