3

This is my code from my layout:

    <adminhtml_customer_edit>
        <reference name="customer_edit_tabs">
            <action method="addTab">
                <name>tabname</name>
                <block>mynamespace_mymodule/adminhtml_customer_tab_tickets</block>
            </action>
        </reference>
    </adminhtml_customer_edit>

I want to hide this tab if I create a new customer and only show on customer edit. How can I do that ? thx

1

One of the ways is to set 'block' variable dynamically via helper. Below is how the code will look like.

layout:

<adminhtml_customer_edit>
    <reference name="customer_edit_tabs">
        <action method="addTab">
            <name>tabname</name>
            <block helper="mynamespace_mymodule/getTabBlock" />
        </action>
    </reference>
</adminhtml_customer_edit>

Mynamespace_Mymodule_Helper_Data:

class Mynamespace_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function getTabBlock()
    {
        $currentCustomer = Mage::registry('current_customer');
        if ($currentCustomer &&  $currentCustomer->getId()) {
            return 'mynamespace_mymodule/adminhtml_customer_tab_tickets';
        } else {
            return [];
        }
    }
}
|improve this answer|||||
  • and what will happen with my block ? adminhtml_customer_tab_tickets, defined in the xml ? – Attila Naghi Dec 7 '16 at 9:11
  • As you can see, the block name will by returned by Mynamespace_Mymodule_Helper_Data::getTabBlock() . In case, you are editing existing customer, it will return 'mynamespace_mymodule/adminhtml_customer_tab_tickets'. And in case of creating a new cstomer, it will return an empty array. – MagestyApps Dec 7 '16 at 11:55

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.