Magento 1.9 – Override Adminhtml Form

adminformadminhtmlmagento-1.9overrides

I must rewrite the Sitemap form in the adminhtml. I must add a new field but I can't display that. I've checked on Google and the results haven't help me.

<?xml version="1.0"?>
<config>
    <modules>
        <Dtlmmage_Sitemap>
            <version>0.7.2</version>
        </Dtlmmage_Sitemap>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sitemap_edit_form>Dtlmmage_Adminhtml_Block_Sitemap_Edit_Form</sitemap_edit_form>
                </rewrite>
            </adminhtml>
        </blocks>
        <models>
            <sitemap>
                <rewrite>
                    <sitemap>Dtlmmage_Sitemap_Model_Sitemap</sitemap>
                </rewrite>
                <resourceModel>sitemap_resource</resourceModel>
            </sitemap>
            <sitemap_resource>
                <rewrite>
                    <catalog_product>Dtlmmage_Sitemap_Model_Resource_Catalog_Product</catalog_product>
                </rewrite>
            </sitemap_resource>
        </models>
    </global>
</config>

<?php
class Dtlmmage_Adminhtml_Block_Sitemap_Edit_Form extends Mage_Adminhtml_Block_Sitemap_Edit_Form
{
    protected function _prepareForm()
    {
        $model = Mage::registry('sitemap_sitemap');
        $form = new Varien_Data_Form();

        $fieldset = $form->addFieldset('add_sitemap_form', array('legend' => Mage::helper('sitemap')->__('Sitemap')));

        $fieldset->addField('sitemap_type', 'select', array(
            'label'    => Mage::helper('sitemap')->__('Type'),
            'name'     => 'sitemap_type',
            'required' => false,
            'value'    => $model->getSitemapCategory(),
            'values'   => array(
                'categories' => 'Catégories, sous-catégories, pages filtrées, pages CMS et guides',
                'products'   => 'Produits',
                'images'     => 'Images',
            ),
        ));
        $this->setForm($form);

        return parent::_prepareForm();


       }
    }

Can you help me to solve the problem?

Thanks

Edit : I've check again on Google and I've found this solution

Best Answer

you should not have to make a rewrite for just adding a field.

You can use an observer event that is called after the _prepareForm Method is executed, then get the form of the block and add a new fieldset with your own fields.

basically like described here: https://www.jyotiranjan.in/blog/add-new-field-magento-admin-form-event-observer/

Related Topic