0

I have another problem.

When you edit an order (admin) you will get here:

enter image description 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?

1

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
  • it worked. Where can I code the logic of the button? – k33n Mar 13 '18 at 14:50
  • you will need to create a new route and a controller that will handle the request – Adrian Z. Mar 13 '18 at 15:32
  • I want the button to start a download – k33n Mar 13 '18 at 15:34
  • you will need to post another question, because that is another topic – Adrian Z. Mar 13 '18 at 15:35

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.