Magento Forum

   
Page 1 of 3
Getting TinyMCE to work
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

1. Firstly download TinyMCE from http://tinymce.moxiecode.com/ (if you already have it installed skip to step 2.)
Extract the zip file and upload the folder tiny_mce folder found in jscripts to magentodir/js

2. Now we need to edit lib/Varien/Data/Form/Element/Editor.php
at about line 45 change the code of getElementHtml to the following

public function getElementHtml()
    
{
        
if($this->getWysiwyg() === true)
        
{
            $element 
= ($this->getState() == 'html') ? '' $this->getHtmlId();

            
$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="'
Mage::getBaseUrl('js').'tiny_mce/tiny_mce.js"></script>
                <script language="javascript" type="text/javascript">
                    Event.observe(window, \'
load\', function() {
                        tinyMCE.init({
                            mode : "exact",
                            strict_loading_mode : true, 
                            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 : "true",
                            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>'
;

                
/*plugins : "inlinepopups,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
                theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,|,visualchars,nonbreaking"*/

            
$html.= $this->getAfterElementHtml();
            return 
$html;
        
}
        
else
        
{
            
return parent::getElementHtml();
        
}
    }

thats about all there is to it. But if you want TinyMCE to work with cms pages too change the line

if($this->getWysiwyg() === true)
to
if($this->getWysiwyg() !== null)

Also if you want to use advanced mode change the function getTheme to the following

public function getTheme()
    
{
        
if(!$this->hasData('theme')) {
            
return 'advanced';
        
}

        
return $this->getData('theme');
    
}

Hope that is of some help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

The second way to achieve this is to edit one of the extensions files.

Install TinyMCE as above then in app/code/community/Monk/Blog/Block/Manage/Blog/Edit/Tab/Form.php at about line 96, change

$fieldset->addField('post_content''editor', array(
            
'name'      => 'post_content',
            
'label'     => Mage::helper('blog')->__('Content'),
            
'title'     => Mage::helper('blog')->__('Content'),
            
'style'     => 'width:700px; height:500px;',
            
'wysiwyg'   => true,
        ));

to this

$fieldset->addField('post_content''editor', array(
            
'name'      => 'post_content',
            
'label'     => Mage::helper('blog')->__('Content'),
            
'title'     => Mage::helper('blog')->__('Content'),
            
'style'     => 'width:700px; height:500px;',
            
'wysiwyg'   => true,
            
            
'after_element_html' => '
                <script language="javascript" type="text/javascript" src="'
Mage::getBaseUrl('js').'tiny_mce/tiny_mce.js"></script>
                <script language="javascript" type="text/javascript">
                    Event.observe(window, \'
load\', function() {
                        tinyMCE.init({
                            mode : "exact",
                            strict_loading_mode : true, 
                            theme : "simple",
                            elements : "post_content",
                            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 : "true",
                            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>'
,
        ));

Enjoy

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lenny2
Sr. Member
 
Total Posts:  171
Joined:  2008-05-21
München
 

Hi Lazzymonk,
thanks for information - works great.
Do you know what to do if we want to use TinyMCE for product description (and short description)?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

i should think it is possible but i dont know how to do it. Not something i have looked into

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lenny2
Sr. Member
 
Total Posts:  171
Joined:  2008-05-21
München
 

ok- thank you anyway…

 
Magento Community Magento Community
Magento Community
Magento Community
 
andreladocruz
Guru
 
Total Posts:  322
Joined:  2008-05-07
Brazil
 

I tried the second way and got the following error:

NoticeUndefined variableelement  in /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/community/Monk/Blog/Block/Manage/Blog/Edit/Tab/Form.php on line 121

#0 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/community/Monk/Blog/Block/Manage/Blog/Edit/Tab/Form.php(121): mageCoreErrorHandler(8, 'Undefined varia...', '/var/www/vhosts...', 121, Array)
#1 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Adminhtml/Block/Widget/Form.php(88): Monk_Blog_Block_Manage_Blog_Edit_Tab_Form->_prepareForm()
#2 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Abstract.php(635): Mage_Adminhtml_Block_Widget_Form->_beforeToHtml()
#3 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/community/Monk/Blog/Block/Manage/Blog/Edit/Tabs.php(19): Mage_Core_Block_Abstract->toHtml()
#4 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Abstract.php(635): Monk_Blog_Block_Manage_Blog_Edit_Tabs->_beforeToHtml()
#5 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Text/List.php(37): Mage_Core_Block_Abstract->toHtml()
#6 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Abstract.php(636): Mage_Core_Block_Text_List->_toHtml()
#7 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Abstract.php(495): Mage_Core_Block_Abstract->toHtml()
#8 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Abstract.php(446): Mage_Core_Block_Abstract->_getChildHtml('left', true)
#9 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/design/adminhtml/default/default/template/page.phtml(51): Mage_Core_Block_Abstract->getChildHtml('left')
#10 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Template.php(138): include('/var/www/vhosts...')
#11 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Template.php(170): Mage_Core_Block_Template->fetchView('adminhtml/defau...')
#12 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Template.php(187): Mage_Core_Block_Template->renderView()
#13 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Block/Abstract.php(636): Mage_Core_Block_Template->_toHtml()
#14 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Model/Layout.php(509): Mage_Core_Block_Abstract->toHtml()
#15 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(320): Mage_Core_Model_Layout->getOutput()
#16 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/community/Monk/Blog/controllers/Manage/BlogController.php(42): Mage_Core_Controller_Varien_Action->renderLayout()
#17 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Controller/Varien/Action.php(343): Monk_Blog_Manage_BlogController->editAction()
#18 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Controller/Varien/Router/Admin.php(137): Mage_Core_Controller_Varien_Action->dispatch('edit')
#19 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/code/core/Mage/Core/Controller/Varien/Front.php(168): Mage_Core_Controller_Varien_Router_Admin->match(Object(Mage_Core_Controller_Request_Http))
#20 /var/www/vhosts/farmadelivery.com.br/httpdocs/app/Mage.php(420): Mage_Core_Controller_Varien_Front->dispatch()
#21 /var/www/vhosts/farmadelivery.com.br/httpdocs/index.php(48): Mage::run()
#22 {main}

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

ill fix that then.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

code above updated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
andreladocruz
Guru
 
Total Posts:  322
Joined:  2008-05-07
Brazil
 

I´ve done the first way and its working!

and for the cms pages too!

thanks a lot!

regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lenny2
Sr. Member
 
Total Posts:  171
Joined:  2008-05-21
München
 

for me the first one also worked…

 
Magento Community Magento Community
Magento Community
Magento Community
 
andreladocruz
Guru
 
Total Posts:  322
Joined:  2008-05-07
Brazil
 

friends…

when creating a new post the system is marking the content field as empty.

please see:

http://www.magentocommerce.com/boards/viewthread/420/P120/

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

Fixed in 0.5.5

 
Magento Community Magento Community
Magento Community
Magento Community
 
GreenSkunk
Jr. Member
 
Avatar
Total Posts:  6
Joined:  2008-04-09
New York
 

For how to apply TinyMCE to a product form please see http://www.magentocommerce.com/wiki/tiny_mce?do=show

@LazzyMonk: What is version 0.5.5? Is there some module that you are placing this code?

Thank you for your time.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

@GreebSkunk. yes its 0.5.5 and no the code is placed in the lib part of magneto. and is there as standard.

 
Magento Community Magento Community
Magento Community
Magento Community
 
marcello13
Member
 
Total Posts:  33
Joined:  2008-07-29
Langnau am Albis / Switzerland
 

Hi Lazzy

The workaround works fine for the blog-pages. But if I then change “true” to “null” than it will not work in blog-pages and in CMS-pages. What do I wrong.

I work with magento 1.1.4.

Thx
Marcello

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

it must be not null.  !== null the ! is important.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 3