3

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...

7

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!

  • Thanyou @AlanStorm for your advice! – user1704524 Aug 2 '14 at 19:00
  • @user1704524 Out of curiosity, what was it? – Alan Storm Aug 2 '14 at 19:05
  • var_dump($tabId, $tab); gives me Fatal error: Call to a member function getUrl() on a non-object in so the saga constinues... – user1704524 Aug 2 '14 at 19:51
  • 1
    Thanks for the post @AlanStorm. FYI in my case this was caused by a custom module having an XML tag which had module="mycustom_modulename" where the module in question didn't have a helper. That old badger. – Robbie Averill Jan 25 '16 at 0:07
1

The approach that worked for me was to have alook at the Exception log as per the answer to this duplicate question:

https://magento.stackexchange.com/a/102173/12662

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.