Setelah mencoba berbagai cara, ini adalah satu-satunya solusi yang dapat saya temukan yang tampaknya berfungsi tanpa mempengaruhi modul lain. Saya akan senang melihat solusi lain.
Pilihan 1
Buat plugin di Perusahaan / Modul / etc / adminhtml / di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Backend\Block\Widget\Button\Toolbar">
<plugin name="MagePal_TestBed::pluginBefore" type="MagePal\TestBed\Plugin\PluginBefore" />
</type>
</config>
Kemudian di Plugin / PluginBefore.php
namespace MagePal\TestBed\Plugin;
class PluginBefore
{
public function beforePushButtons(
\Magento\Backend\Block\Widget\Button\Toolbar\Interceptor $subject,
\Magento\Framework\View\Element\AbstractBlock $context,
\Magento\Backend\Block\Widget\Button\ButtonList $buttonList
) {
$this->_request = $context->getRequest();
if($this->_request->getFullActionName() == 'sales_order_view'){
$buttonList->add(
'mybutton',
['label' => __('My Button'), 'onclick' => 'setLocation(window.location.href)', 'class' => 'reset'],
-1
);
}
}
}
pilihan 2
Buat plugin di Perusahaan / Modul / etc / adminhtml / di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="\Magento\Sales\Block\Adminhtml\Order\View">
<plugin name="MagePal_TestBed::pluginBeforeView" type="MagePal\TestBed\Plugin\PluginBeforeView" />
</type>
</config>
Kemudian di Plugin / PluginBeforeView.php
namespace MagePal\TestBed\Plugin;
class PluginBeforeView
{
public function beforeGetOrderId(\Magento\Sales\Block\Adminhtml\Order\View $subject){
$subject->addButton(
'mybutton',
['label' => __('My Buttion'), 'onclick' => 'setLocation(window.location.href)', 'class' => 'reset'],
-1
);
return null;
}
}
Lihat Kode Sumber Lengkap