Add HTML edit - wysiwyg Field in custom module

1. rewrite adminhtml router:

<config>
 <admin>
	<routers>
		 <adminhtml>
                <args>
                    <modules>
                        <Bysoft_Myfaq_Adminhtml before="Mage_Adminhtml">Bysoft_Myfaq_Adminhtml</Bysoft_Myfaq_Adminhtml>
                    </modules>
                </args>
            </adminhtml>	
	</routers>
  </admin>
  <adminhtml>
	<menu>
	  <myfaq module="myfaq">
		<title>FAQ</title>
		<sort_order>100</sort_order>
		<children>
		  <myfaq module="myfaq">
		    <title>Manage FAQ</title>
			<sort_order>0</sort_order>
			<action>adminhtml/myfaq</action>
		  </myfaq>
		</children>
	  </myfaq>
	</menu>
	<acl>
	  <resources>
		<all>
		  <title>Allow Everything</title>
		</all>
		<admin>
		  <children>
			<myfaq translate="title" module="myfaq">
			  <title>Myfaq</title>
			  <sort_order>1000</sort_order>
			  <children>
		  <myfaq translate="title">
			<title>Manage Myfaq</title>
			<sort_order>0</sort_order>
		  </myfaq>
			  </children>
			</myfaq>
		  </children>
		</admin>
	  </resources>
	</acl>
	<layout>
	  <updates>
		<myfaq>
		  <file>myfaq.xml</file>
		</myfaq>
	  </updates>
	</layout>
  </adminhtml>

 

2. add css and js to adminhtml layout file:

<?xml version="1.0"?>
<layout version="0.1.0">
  
    <adminhtml_myfaq_index>
    	<update handle="myfaq_index_index"/>
		<reference name="content">
		  <block type="myfaq/adminhtml_myfaq" name="myfaq" />
		</reference>
  </adminhtml_myfaq_index>
  
    <adminhtml_myfaq_edit>
            <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="addCss"><name>lib/prototype/windows/themes/magento.css</name></action>
            </reference> 
  </adminhtml_myfaq_edit>
  <adminhtml_myfaq_new>
            <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="addCss"><name>lib/prototype/windows/themes/magento.css</name></action>
            </reference> 
  </adminhtml_myfaq_new>
</layout>

 3. enable wysiwyg_config in Bysoft_Myfaq_Block_Adminhtml_Myfaq_Edit_Tab_Form _prepareLayout function

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

 

3. add wysiwyg field  in Bysoft_Myfaq_Block_Adminhtml_Myfaq_Edit_Tab_Form class function _prepareForm()

protected function _prepareForm() {
    //....
    $fieldset->addField('answer', 'editor', array(
					'name' => 'description',
					'label' => Mage::helper("myfaq")->__('Answer'),
					'title' => Mage::helper("myfaq")->__('Answer'),
					'style' => 'height:25em',
					'wysiwyg' => true,
					'required' => true,
					'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
			));
    //....
}

 

 

   

你可能感兴趣的:(Module)