wyswingeditorincustom
Step-1

Go to following path and open Edit.php

app\code\local\Namespace\Modulename\Block\Adminhtml\Modulename\Edit.php

and Add this Function:

protected function _prepareLayout(){
    // Load Wysiwyg on demand and Prepare layout
    if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled() && ($block = $this->getLayout()->getBlock('head'))) {
        $block->setCanLoadTinyMce(true);
    }
    parent::_prepareLayout();
}

Step-2

Go to following path and open Form.php

app\code\local\Namespace\Modulename\Block\Adminhtml\Modulename\Edit\Tab\Form.php

Find the function protected function_prepareForm() and add the following after

$form = new Varien_Data_Form();
      $this->setForm($form);
$form->setHtmlIdPrefix('banner');
$wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array('tab_id' => 'form_section'));
$wysiwygConfig["files_browser_window_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg_images/index');
$wysiwygConfig["directives_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive');
$wysiwygConfig["directives_url_quoted"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/cms_wysiwyg/directive');
$wysiwygConfig["widget_window_url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/widget/index');
$wysiwygConfig["files_browser_window_width"] = (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_width');
$wysiwygConfig["files_browser_window_height"] = (int) Mage::getConfig()->getNode('adminhtml/cms/browser/window_height');

$plugins = $wysiwygConfig->getData("plugins");
$plugins[0]["options"]["url"] = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_variable/wysiwygPlugin');
$plugins[0]["options"]["onclick"]["subject"] = "MagentovariablePlugin.loadChooser('".Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/system_variable/wysiwygPlugin')."', '{{html_id}}');";
$plugins = $wysiwygConfig->setData("plugins",$plugins);

And add this code to display wysiwyg editor:

$fieldset->addField('content', 'editor', array(
          'name'      => 'content',
          'label'     => Mage::helper('banner')->__('Content'),
          'title'     => Mage::helper('banner')->__('Content'),
          'wysiwyg'   => true,
          'required'  => true,
          'style' => 'width:700px; height:500px;',
          'state'     => 'html',
          'config'    => $wysiwygConfig,
      ));

Step-3:

Go to following path and open yourmodulename.xml if its not available than create xml file

app\design\adminhtml\default\default\layout\yourmodulename.xml

And add:

<?xml version="1.0"?>
<layout version="0.1.0">
    <banner_adminhtml_banner_index>
        <reference name="content">
            <block type="banner/adminhtml_banner" name="banner" />
        </reference>
    </banner_adminhtml_banner_index>
    <banner_adminhtml_banner_edit>
        <update handle="editor"/>
    </banner_adminhtml_banner_edit>
        
</layout>

where first banner is module name and second banner is model name . Bingo you have working wysiwyg editor in magento working-on-a-computer-smiley-emoticon

Categories: Magento

0 Comments

Leave a Reply

Avatar placeholder

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