Add custom button to Pageactions
-
03-01-2021 - |
Question
I have another problem.
When you edit an order (admin) you will get here:
The buttons above, marked with the red line, are generated here:
/module-backend/view/adminhtml/templates/pageactions.phtml
Magento\Framework\View\Element\Template
// @codingStandardsIgnoreFile
?>
<?php if ($block->getChildHtml()):?>
<div data-mage-init='{"floatingHeader": {}}' class="page-actions" <?php /* @escapeNotVerified */ echo $block->getUiId('content-header') ?>>
<?php echo $block->getChildHtml(); ?>
</div>
<?php endif; ?>
I want to add a custom button "Bestellschein" there. How can I do that?
Edit: Where can I code the logic of the button?
La solution
One way you can do that is by adding a plugin to your project. Create:
\app\code\Custom\Module\registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Custom_Module',
__DIR__
);
\app\code\Custom\Module\etc\module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Custom_Module" setup_version="1.0.0"/>
</config>
\app\code\Custom\Module\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="buttons_plugin" type="Custom\Module\Plugin\Buttons" />
</type>
</config>
\app\code\Custom\Module\Plugin\Buttons.php
namespace Custom\Module\Plugin;
class Buttons
{
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
);
}
}
}
After run:
- php bin/magento setup:upgrade
- php bin/magento cache:flush
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange