在Magento的CMS页面的所见即所得编辑器上,有一个工具可以将Magento小部件添加到编辑器中。我希望这个功能也可以在产品和类别描述的所见即所得编辑器中使用。
我现在无法找到编辑器加载的位置。请问有人能告诉我该怎么做或至少指点一下方向吗?
提前感谢。
我现在无法找到编辑器加载的位置。请问有人能告诉我该怎么做或至少指点一下方向吗?
提前感谢。
![enter image description here](https://istack.dev59.com/UNeHB.webp)
Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content
类中的 add_widgets
和 add_variables
后,您可能会发现虽然这确实会在所见即所得编辑器中启用它们并正常工作,但它在前端只会呈现原始的小部件/变量代码(而不是适当的标记)。/app/design/frontend/package/theme/template/catalog/category/view.phtml
查找 <?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
在此行下面添加以下内容:<?php
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$_description = $processor->filter($_description);
?>
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 config 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 handler that will process content from 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 Observer wich add handlers for out 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);
}
}
完整的代码快照请查看链接https://github.com/popovsergiy/magento-wysiwyg
我认为更好的方法是创建一个新的观察者来监听相同的事件,并使模块依赖于Mage_Widget。然后我们的观察者将在Mage_Widget之后运行