Fix Wrong Tab Configuration Error in Magento

adminhtmlblocksoverridestabs

I am trying to extend Mage_Adminhtml_Block_Customer_Edit_Tab_View class in order to pass in some functions and display them using a layout update in

adminhtml/default/default/template/namespace/mymodule/edit/tab/view.phtml

I've used a rewrite in my config.xml

<blocks>
    <mymodule>
        <class>Mymodule_Customer_Block</class>
    </mymodule>
    <adminhtml>
        <rewrite>
            <customer_edit_tab_view>Mymodule_Customer_Block_Adminhtml_Customer_Edit_Tab_View</customer_edit_tab_view>
        </rewrite>
    </adminhtml>
</blocks>

And here is the View.php file

class Mymodule_Customer_Block_Adminhtml_Customer_Edit_Tab_View extends   Mage_Adminhtml_Block_Customer_Edit_Tab_View
{
    public function getCredit(){

        $customerId = $this->getCustomer()->getId();
        $model = Mage::registry('current_customer');
        $customerId = $model->getId();
        $data = $model->getData();

        $helper = Mage::helper('customercredit');
        $creditValue = (float)$helper->getCreditValue($customerId, $model->getWebsiteId());

        return $creditValue;
    }    
}

Whenever I go to view the customer edit view tab in magento admin I get an error:

Wrong tab configuration.

I must have missed something out of my setup but I am not sure what?

Any one have any idea please let me know…

Best Answer

You'll need to do a little detective work. It's very possible a different change is responsible for the error you're seeing, or that something about your replacement triggers this error.

To start, I'd remove any custom functions you have in Mymodule_Customer_Block_Adminhtml_Customer_Edit_Tab_View and concentrate on getting the class rewrite working without a Wrong tab Configuration exception — that way if the error is tied to a method you've added, you'll know which one when you add your methods back one by one.

The exception you're seeing comes from this method

#File: app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php
public function addTab($tabId, $tab)
{
    if (is_array($tab)) {
        $this->_tabs[$tabId] = new Varien_Object($tab);
    }
    elseif ($tab instanceof Varien_Object) {
        $this->_tabs[$tabId] = $tab;
        if (!$this->_tabs[$tabId]->hasTabId()) {
            $this->_tabs[$tabId]->setTabId($tabId);
        }
    }
    elseif (is_string($tab)) {
        if (strpos($tab, '/')) {
            $this->_tabs[$tabId] = $this->getLayout()->createBlock($tab);
        }
        elseif ($this->getChild($tab)) {
            $this->_tabs[$tabId] = $this->getChild($tab);
        }
        else {
            $this->_tabs[$tabId] = null;
        }

        if (!($this->_tabs[$tabId] instanceof Mage_Adminhtml_Block_Widget_Tab_Interface)) {
            throw new Exception(Mage::helper('adminhtml')->__('Wrong tab configuration.'));
        }
    }
    else {
        throw new Exception(Mage::helper('adminhtml')->__('Wrong tab configuration.'));
    }

    if (is_null($this->_tabs[$tabId]->getUrl())) {
        $this->_tabs[$tabId]->setUrl('#');
    }

    if (!$this->_tabs[$tabId]->getTitle()) {
        $this->_tabs[$tabId]->setTitle($this->_tabs[$tabId]->getLabel());
    }

    $this->_tabs[$tabId]->setId($tabId);
    $this->_tabs[$tabId]->setTabId($tabId);

    if (is_null($this->_activeTab)) $this->_activeTab = $tabId;
    if (true === $this->_tabs[$tabId]->getActive()) $this->setActiveTab($tabId);

    return $this;
}

And occurs when Magento can't instantiate a tab from information passed into addTab. My guess is your error comes from this bit of layout XML in catalog.xml

<action method="addTab"><name>customer_edit_tab_view</name><block>customer_edit_tab_view</block></action>

Although adding some temporary debugging to the addTab method above will help with that

var_dump($tabId, $tab);

If that's the case, it sounds like Magento may be having trouble instantiating your new block class. I'd try running the following code

$block = new Mymodule_Customer_Block_Adminhtml_Customer_Edit_Tab_View;
var_dump($block);

$block = Mage::getSingleton('adminhtml/customer_edit_tab_view');
var_dump($block);

and looking for instantiation errors (each call should return a block object).

My best guess as to why this is happening is you have your View.php file for Mymodule_Customer_Block_Adminhtml_Customer_Edit_Tab_View created in the wrong folder.

Good luck!

Related Topic