I am attempting to add a custom field to the Magento CMS page editor using this guide, but I am not able to get the additional field to display in the backend.
Here are the files I have created:
ddog_customcms.xml in /app/etc/modules
<config>
<modules>
<ddog_customcms>
<active>true</active>
<codePool>local</codePool>
<depends/>
</ddog_customcms>
</modules>
</config>
config.xml in /app/code/local/ddog/customcms/etc
<?xml version="1.0"?>
<config>
<modules>
<ddog_customcms>
<version>1.0.0</version>
</ddog_customcms>
</modules>
<global>
<models>
<ddog_customcms>
<class>ddog_customcms_Model</class>
</ddog_customcms>
</models>
<events>
<adminhtml_cms_page_edit_tab_content_prepare_form>
<observers>
<ddog_customcms_page_edit_tab_content>
<type>singleton</type>
<class>ddog_customcms_Model_Observer</class>
<method>cmsField</method>
</ddog_customcms_page_edit_tab_content>
</observers>
</adminhtml_cms_page_edit_tab_content_prepare_form>
</events>
<resources>
<ddog_customcms_setup>
<setup>
<module>ddog_customcms</module>
</setup>
</ddog_customcms_setup>
</resources>
</global>
</config>
content_custom column added to cms_page database table
observer.php in /app/code/local/ddog/customcms/Model/
<?php
class ddog_customcms_observer
{
public function addNewCmsField($observer)
{
//get CMS model with data
$model = Mage::registry('cms_page');
//get form instance
$form = $observer->getForm();
//create new custom fieldset 'ddog_customcms_content_fieldset'
$fieldset = $form->addFieldset('ddog_customcms_content_fieldset', array('legend'=>Mage::helper('cms')->__('Custom'),'class'=>'fieldset-wide'));
//add new field
$fieldset->addField('content_custom', 'text', array(
'name' => 'content_custom',
'label' => Mage::helper('cms')->__('Content Custom'),
'title' => Mage::helper('cms')->__('Content Custom'),
'disabled' => false,
//set field value
'value' => $model->getContentCustom()
));
}
}
I have cleared the cache but I can't get the field to appear anywhere in the page editor. Can anybody help?
here in declaration
<events>
<adminhtml_cms_page_edit_tab_content_prepare_form>
<observers>
<ddog_customcms_page_edit_tab_content>
<type>singleton</type>
<class>ddog_customcms_Model_Observer</class>
<method>cmsField</method>
</ddog_customcms_page_edit_tab_content>
</observers>
</adminhtml_cms_page_edit_tab_content_prepare_form>
</events>
you set method name cmsField
but in observer you write method name addNewCmsField
change it to cmsField
and it will work
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.