Adding new button from observer issue
-
01-01-2021 - |
Pregunta
I am using this event to add a new button:
controller_action_layout_render_before_adminhtml_sales_billing_agreement_view
This is my function:
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
if (!$block = Mage::app()->getLayout()->getBlock('adminhtml_sales_billing_agreement_view')) {
return $this;
}
$block->addButton('test',[
'label' => Mage::helper('mynamespace_mymodule')->__('Test'),
'class' => 'test'
]);
return $this;
The result of my var_dump
is
array(4) { [0]=> string(7) "default" [1]=> string(11) "STORE_admin" [2]=> string(31) "THEME_adminhtml_default_default" [3]=> string(38) "adminhtml_sales_billing_agreement_view" }
. But I cannot get my block, it doesn't get to the point to add my new button. It always returns $this
.
Maybe my block name is incorrect. Any idea ?
Thank you
Solución
Please try this:
- change event to
adminhtml_block_html_before
observer code
if ($block->getType() == 'sales/adminhtml_billing_agreement_view') { $block->addButton('test', array( 'label' => 'Test', 'class' => 'test' )); }
Otros consejos
Using this event: adminhtml_widget_container_html_before
and in the function called :
public function adminhtmlWidgetContainerHtmlBefore(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if ($block instanceof your_class_here) {
$block->addButton('truncate_quote', array(
'label' => Mage::helper('mynamespace_mymodule')->__('Your Label Name'),
'class' => 'go'
));
//or remove a button
$block->removeButton('your button');
}
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange