Question

Here's my folder structure for my block:

Product
| - Form.php
Product.php

My product form is a Form Container which is supposed to launch the Form stored within Product -> Form.php

However, although Product.php is loading fine, the Product -> Form.php does not seem to be appearing. I have a simple form setup, with a simple field on there asking for a Product SKU. The Fieldset nor the form it's contained within are loading on the page.

<?php
/**
 * Form for Warehouse Products.
 * Loads individual items that make up the form itself.
 *
 * @author Dan Hanly
 **/
class Company_Module_Block_Adminhtml_Warehouse_Edit_Product_Form extends Mage_Adminhtml_Block_Widget_Form
{
    public $_id;        // Identifier of the block
    public $_title;     // Title of the block
    public $_form;      // Varien_Data_Form

    /**
     * Init class
     */
    public function __construct()
    {
        parent::__construct();

        $this->_id = 'product_form';
        $this->_title = $this->__('Product Information');
    }

    /**
     * Setup form fields for inserts/updates
     *
     * @return Mage_Adminhtml_Block_Widget_Form
     * @author Dan Hanly
     */
    public function _prepareForm()
    {
        $model = Mage::registry('module_warehouse');
        $request = $this->getRequest();

        $this->_form = $this->createForm($this->getUrl('*/*/save', $this->getUrlParameters($request)));
        $this->setForm($this->_form);

        $fieldset = $this->_form->addFieldset('base_fieldset', array(
            'legend' => $this->_title,
            'class' => 'fieldset-wide',
        ));

        if ($this->isEdit($request)) {
            $fieldset->addField('id', 'hidden', array(
                'name' => 'id',
            ));
        }

        $fieldset->addField('warehouse_id', 'hidden', array(
            'name' => 'warehouse_id',
            'value' => Mage::registry('module_warehouse')->getId()
        ));

        $fieldset->addField('product_id', 'text', array(
            'name' => 'product_id',
            'label' => $this->__('Choose Product'),
            'value' => $this->__('Choose Product'),
        ));

        return parent::_prepareForm();
    }

There's nothing relevant in the logs that would allude to this.

EDIT
I clarified my question to strip out parts that were irrelevant.

Was it helpful?

Solution

I have resolved the issue.

Essentially, Magento automatically looks for a Form Container's Form within an Edit folder. So as my Form was stored within the Product folder, it wasn't displaying.

There is a class variable in the Mage_Adminhtml_Block_Widget_Form_Container class called $this->_mode. This variable defaults to 'edit' - this alone influences the form container's search for a class in the Edit folder.

Within my form container class, I was able to override the _mode variable, providing 'product' as it's value. Now, everything is connected up as it should be.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top