Module error message: MediabrowserUtility is not defined

If you install a custom module in Magento it could lack the TinyMce Mediabrowser. You get the following message then:

error: error in [unknown object].fireEvent():

event name: open_browser_callback

error message: MediabrowserUtility is not defined

How to fix this?

Quick fix

In /app/design/adminhtml/default/default/layout/YOURMODULE.xml add:

<reference name="head">
            <action method="setCanLoadExtJs"><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="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>
            <action method="addCss"><stylesheet>lib/prototype/windows/themes/magento.css</stylesheet></action>
            
        </reference>

Or change to

Long solution (may not work)

In your /YOURMODULE/etc/config.xml you have:

 
  &lt;cms_wysiwyg_config_prepare&gt;

      &lt;variable_observer&gt;
        core/variable_observer
        prepareWysiwygPluginConfig

In Block/Adminhtml/YOURMODULE/Edit.php

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

Then in the top of Block/Adminhtml/YOURMODULE/Edit/Tab/Form.php

 protected function _prepareForm() {
            $form = new Varien_Data_Form();
            $this-&gt;setForm($form);
            $wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')-&gt;getConfig(array('add_variables' =&gt; false,
         'add_widgets' =&gt; false,
          'add_images' =&gt; true,
          'files_browser_window_url' =&gt; Mage::getSingleton('adminhtml/url')-&gt;getUrl('adminhtml/cms_wysiwyg_images/index'),
          'files_browser_window_width' =&gt; (int) Mage::getConfig()-&gt;getNode('adminhtml/cms/browser/window_width'),
          'files_browser_window_height'=&gt; (int) Mage::getConfig()-&gt;getNode('adminhtml/cms/browser/window_height')
         ));

Further down:

$fieldset-&gt;addField('not-called-content', 'editor', array(
                                    'name'      =&gt; 'not-called-content',
                                    'label'     =&gt; Mage::helper('WHATEVER')-&gt;__('Content'),
                                    'title'     =&gt; Mage::helper('WHATEVER')-&gt;__('Content'),
                                    'style'     =&gt; 'width:550px; height:300px;',
                                    'required'  =&gt; false,
                                    'config'    =&gt; $wysiwygConfig,
                                    'wysiwyg'   =&gt; true
                                    ));

With thanks to Theodores

One thought on “Module error message: MediabrowserUtility is not defined”

  1. Thank you very much for this. I’ve had to reference this more than once now and it has helped save me hours of frustration every time.

Leave a Reply

Your email address will not be published. Required fields are marked *