Magento: Add the Widget Tool to the WYSIWYG Product and Category

The WYSIWYG editor for Magento CMS pages has a tool for adding a Magento widget to the editor. I would like it to be also available for WYSIWYG in the product and category descriptions.

I'm struggling to find where the editor is even loaded at the moment. Can someone let me know what I need to do, or at least point me in the right direction?

Thanks in advance.

enter image description here

+4
source share
4 answers

In the class Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content there are two flags in the configuration array add_widgets and add_variables. By default, both are set to false.

Setting these values ​​to true will be clamped in the function of the Mage_Widget_Model_Observer class prepareWidgetsPluginConfig in the cms_wysiwyg_config_prepare event.

I would suggest rewriting Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content according to your needs, but setting add_widgets and add_variables to true should work for both categories and products.

+4
source

After enabling add_widgets and add_variables in the Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content class according to the answer of @David Manner, you will most likely find that although this will certainly enable them in the WYSIWYG editor and will work correctly, it will only display the code that does not work; end (and not the corresponding markup).

You can fix the following: -

Go to /app/design/frontend/package/theme/template/catalog/category/view.phtml

Find <?php if($_description=$this->getCurrentCategory()->getDescription()): ?>

Add the following line below: -

 <?php $helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $_description = $processor->filter($_description); ?> 

This will display in the interface correctly.

+6
source

After reading all the answers, I found an elegant solution. This solution overwrites only one Block class and does not modify the template file.

  • Rewrite Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content

    <config> ... <global> <blocks> ... <adminhtml> <rewrite> <catalog_helper_form_wysiwyg_content>Agere_Wysiwyg_Block_Widget_Anywhere</catalog_helper_form_wysiwyg_content> </rewrite> </adminhtml> </blocks> ... </global> </config>

  • Change only two flags in the configuration array "add_widgets" and "add_variables" to true

     class Agere_Wysiwyg_Block_Widget_Anywhere extends Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content { protected function _prepareForm() { //return parent::_prepareForm(); $form = new Varien_Data_Form(array('id' => 'wysiwyg_edit_form', 'action' => $this->getData('action'), 'method' => 'post')); $config['document_base_url'] = $this->getData('store_media_url'); $config['store_id'] = $this->getData('store_id'); $config['add_variables'] = true; $config['add_widgets'] = true; $config['add_directives'] = true; $config['use_container'] = true; $config['container_class'] = 'hor-scroll'; $form->addField($this->getData('editor_element_id'), 'editor', array( 'name' => 'content', 'style' => 'width:725px;height:460px', 'required' => true, 'force_load' => true, 'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig($config) )); $this->setForm($form); return $this; } } 
  • Create a handler that will process content from a category or product

     class Agere_Wysiwyg_Helper_Filter extends Mage_Core_Helper_Abstract { public function categoryAttribute($mainHelper, $result, $params) { return $this->process($result); } public function productAttribute($mainHelper, $result, $params) { return $this->process($result); } public function process($result) { /** @var Mage_Cms_Helper_Data $helperCms */ $helperCms = Mage::helper('cms'); $processor = $helperCms->getPageTemplateProcessor(); return $processor->filter($result); } } 
  • Finally, create an Observer that will add handlers for wysiwyg

     class Agere_Wysiwyg_Model_Observer extends Varien_Event_Observer { public function addWysiwygHandler(Varien_Event_Observer $observer) { /** @var Mage_Catalog_Helper_Output $_helperOutput */ /** @var Agere_Wysiwyg_Helper_Filter $_helperFilter */ $_helperOutput = Mage::helper('catalog/output'); $_helperFilter = Mage::helper('agere_wysiwyg/filter'); $_helperOutput->addHandler('categoryAttribute', $_helperFilter); $_helperOutput->addHandler('productAttribute', $_helperFilter); } } 

For complete code binding, see https://github.com/popovsergiy/magento-wysiwyg

+1
source

Think that the best way is to create a new observer that listens for the same event and make a module depending on Mage_Widget. Then our observer will work after Mage_Widget

0
source

All Articles