Using Magento 1.4 WYSIWYG Editor on Custom Administration Pages

Does anyone know how to get the new 1.4 WYSIWYG editor (TinyMCE) that works with custom admin pages?

I have some modules that I created that have input fields in the admin-> system-> config section, and Id like the new editor to appear in text areas, but I cannot find where they are defined.

+3
source share
5 answers

To load TINY MCE on a specific page, use the following function in the Edithtml Edit block of the module:

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

, 'wysiwyg' = > true, 'wysiwyg' = > false. ..:

$fieldset->addField('description', 'editor', array(
    'name'      => 'description',
    'label'     => Mage::helper('sevents')->__('Description'),
    'title'     => Mage::helper('sevents')->__('Description'),
    'style'     => 'height:12em;width:500px;',
    'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
    'wysiwyg'   => true,
    'required'  => true,
)); 
+6

, TinyMCE CMS Magento.

1.

Download TinyMCE root/js. . ( jQuery) TinyMCE. , Magento Prototype, . -, . tiny_mce.js js/tiny_mce/tiny_mce.js.

2.

app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php.
 $fieldset->addField('content', 'editor', array(
        'name'      => 'content',
        'label'     => Mage::helper('cms')->__('Content'),
        'title'     => Mage::helper('cms')->__('Content'),
        'style'     => 'height:36em;',
        'wysiwyg'   => false,
        'required'  => true,
    ));

 $fieldset->addField('content', 'editor', array(
        'name'      => 'content',
        'label'     => Mage::helper('cms')->__('Content'),
        'title'     => Mage::helper('cms')->__('Content'),
        'style'     => 'height:36em;',
        'wysiwyg'   => true,
        'theme' => 'advanced',
        'required'  => true,
    ));

, ( "wysiwyg" ) "".

3.

/lib/Varien/Data/Form/Element/Editor.php getElementHtml().
 $html = '
    <textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
    <script type="text/javascript">
        // <![CDATA[
            /* tinyMCE.init({
                mode : "exact",
                theme : "'.$this->getTheme().'",
                elements : "' . $element . '",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_path_location : "bottom",
                extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
                theme_advanced_resize_horizontal : "false",
                theme_advanced_resizing : "false",
                apply_source_formatting : "true",
                convert_urls : "false",
                force_br_newlines : "true",
                doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
            });*/
        //]]>
    </script>';

 $html = '
    <textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
    <script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
    //< ![CDATA[
        Event.observe(window, "load", function() {
            tinyMCE.init({
                mode : "exact",
                theme : "'.$this->getTheme().'",
                elements : "' . $element . '",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_path_location : "bottom",
                extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
                theme_advanced_resize_horizontal : "false",
                theme_advanced_resizing : "false",
                apply_source_formatting : "true",
                convert_urls : "false",
                force_br_newlines : "true",
                doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
            });
        });
    //]]>
    </script>';

, (, , ), TinyMCE .

, . .

& ; Branko Ajzele ()

+2

EW_Press_Block_Adminhtml_Press_Edit (///Adminhtml//edit.php)

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

.php(EW_Press_Block_Adminhtml_Press_Edit_Tab_Form) /(EW/Press/Block/Adminhtml/Press/Edit/Tab/Form.php)/

'config' = > Mage:: getSingleton ('cms/wysiwyg_config') β†’ getConfig(),

, :

$fieldset->addField('content', 'editor', array(
          'name'      => 'content',
          'label'     => Mage::helper('module')->__('Site Description'),
          'title'     => Mage::helper('module')->__('Site Description'),
          'style'     => 'width:400px; height:300px;',
          'required'  => true,
          'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
          'wysiwyg'   => true
      ));

, .

+1

, .

, //​​/Mynamespace/MyModule/Block/Adminhtml/MyModule/edit.php

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

//​​/Mynamespace/MyModule/Block/Adminhtml/MyModule/Edit/Tab/form.php

'_prepareForm()'

$config = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array(
'add_widgets' => false,
'add_variables' => false,
'add_images' => false,
'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/',
));



$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('mymodule')->__('Content'),
'title' => Mage::helper('mymodule')->__(’Content'),
'style’ => 'width:700px; height:320px;',
'wysiwyg' => true,
'required' => true,
'config' => $config,
));
+1

Source: https://habr.com/ru/post/1734413/


All Articles