MagentoのCMSページ用のWYSIWYGエディターには、Magentoウィジェットをエディターに追加するためのツールがあります。WYSIWYGでも、製品とカテゴリの説明でこれを利用できるようにしたいと思います。
現在、エディターがロードされている場所を見つけるのに苦労しています。誰かが私に何をしなければならないかを教えてもらえますか、少なくとも私を正しい方向に向けることができますか?
前もって感謝します。
MagentoのCMSページ用のWYSIWYGエディターには、Magentoウィジェットをエディターに追加するためのツールがあります。WYSIWYGでも、製品とカテゴリの説明でこれを利用できるようにしたいと思います。
現在、エディターがロードされている場所を見つけるのに苦労しています。誰かが私に何をしなければならないかを教えてもらえますか、少なくとも私を正しい方向に向けることができますか?
前もって感謝します。
@David Mannerの回答に従って有効add_widgets
にadd_variables
してクラスに入れると、WYSIWYGエディターでこれらが確実に有効になり、正しく機能する一方で、(適切なものではなく)フロントエンドで生のウィジェット/変数コードのみがレンダリングされることがわかります。Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Content
マークアップ)。
次の方法で修正できます:-
案内する/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);
?>
これにより、フロントエンドで正しくレンダリングされます。
クラスMage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Contentの下には、構成配列「add_widgets」と「add_variables」に2つのフラグがあります。これらは両方ともデフォルトでfalseに設定されています。
これらをtrueに設定すると、イベントcms_wysiwyg_config_prepareのMage_Widget_Model_Observerクラス関数prepareWidgetsPluginConfigでキャッチされます。
Mage_Adminhtml_Block_Catalog_Helper_Form_Wysiwyg_Contentをニーズに合わせて書き直すことをお勧めしますが、add_widgetsとadd_variablesをtrueに設定すると、カテゴリと製品の両方で機能するはずです。
すべての答えを読んだ後、私はエレガントな解決策を見つけました。このソリューションは、1つのBlockクラスのみを書き換え、テンプレートファイルを変更しません。
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>
構成配列'add_widgets'および'add_variables'の2つのフラグのみを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;
}
}
カテゴリまたは製品のコンテンツを処理するハンドラーを作成します
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);
}
}
最後に、outwysiwygのハンドラーを追加するオブザーバーを作成します
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の後に実行されます