2

I m trying to use a new field in cms block . it insert well in database , and i can see it on the grid but , in edit i can t see the new field. I already did it for the cms page and it works . i used an observer and not a rewrite like this :

    class Upecom_Cmstype_Model_Observer
    {
 public function cmsField(Varien_Event_Observer $observer)
    {
        //get form instance
        $form = $observer->getForm();
        $fieldset = $form->getElement('base_fieldset');

        //add new field
        $fieldset->addField('type_page', 'select', array(
            'name'      => 'type_page',
            'label'     => Mage::helper('cms')->__('Type Page'),
            'title'     => Mage::helper('cms')->__('Type Page'),
            'disabled'  => false,
            'readonly' => false,
            'required'  => true,
            'options'   => Mage::getSingleton('upecom_cmstype/page')->getAvailableTypePages()
        ));
    }
        /**
         *  add the field cms_type in the backoffice
         * @param Varien_Event_Observer $observer
         *
         */
        public function cmsFieldBlock(Varien_Event_Observer $observer)
        {

            //get form instance
            $form = $observer->getForm();
            $fieldset = $form->getElement('base_fieldset');

            //add new field
            $fieldset->addField('type_block', 'select', array(
                'name'      => 'type_block',
                'label'     => Mage::helper('cms')->__('Type Block'),
                'title'     => Mage::helper('cms')->__('Type Block'),
                'disabled'  => false,
                'readonly' => false,
                'required'  => true,
                'options'   => Mage::getSingleton('upecom_cmstype/block')->getAvailableTypeBlocks()
            ));
        }
    }

And my config.xml is :

 <global>
        <events>
            <adminhtml_cms_block_edit_form_prepare_form>
                <observers>
                    <upecom_page_edit_form>
                        <type>singleton</type>
                        <class>Upecom_Cmstype_Model_Observer</class>
                        <method>cmsFieldBlock</method>
                    </upecom_page_edit_form>
                </observers>

            </adminhtml_cms_block_edit_form_prepare_form>

<adminhtml_cms_page_edit_tab_main_prepare_form>
            <observers>
                <upecom_page_edit_tab_main>
                    <type>singleton</type>
                    <class>Upecom_Cmstype_Model_Observer</class>
                    <method>cmsField</method>
                </upecom_page_edit_tab_main>
            </observers>
        </adminhtml_cms_page_edit_tab_main_prepare_form>

Where is my mistake ? I can see the event adminhtml_cms_block_edit_form_prepare_form in core/mage/adminhtml/block/cms/block/edit/form.php

Thank you

1

For CMS Block try this event

<adminhtml_block_html_before>
    <observers>
        <upecom_page_edit_form>
            <type>singleton</type>
            <class>Upecom_Cmstype_Model_Observer</class>
            <method>cmsFieldBlock</method>
        </upecom_page_edit_form>
    </observers>
</adminhtml_block_html_before>

In your observer file change to this code

public function cmsFieldBlock(Varien_Event_Observer $observer)
{
    $block = $observer->getEvent()->getBlock();
    if ($block->getType() == 'adminhtml/cms_block_edit_form') {
        //get form instance
        $form = $block->getForm();
        $fieldset = $form->getElement('base_fieldset');

        //add new field
        $fieldset->addField('type_block', 'select', array(
            'name'      => 'type_block',
            'label'     => Mage::helper('cms')->__('Type Block'),
            'title'     => Mage::helper('cms')->__('Type Block'),
            'disabled'  => false,
            'readonly' => false,
            'required'  => true,
            'options'   => Mage::getSingleton('upecom_cmstype/block')->getAvailableTypeBlocks()
        ));
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.