6

I want to remove the Create Order button from the admin customer edit form and I don't know how to do this via a plugin or an event.

The button is added from Magento\Customer\Block\Adminhtml\Edit::_construct and I cannot write a plugin for a protected method.
Is there an event, or a public method that is called after the buttons are added and before the layout is rendered that I can use?

7

After test I think it work with Magento\Customer\Block\Adminhtml\Edit\OrderButton and not Magento\Customer\Block\Adminhtml\Edit it has public function:

public function getButtonData()
{
    $customerId = $this->getCustomerId();
    $data = [];
    if ($customerId && $this->authorization->isAllowed('Magento_Sales::create')) {
        $data = [
            'label' => __('Create Order'),
            'on_click' => sprintf("location.href = '%s';", $this->getCreateOrderUrl()),
            'class' => 'add',
            'sort_order' => 40,
        ];
    }
    return $data;
}

you can use plugin is public function

1
  • 1
    You are right. I can pluginize that method using around plugin and make my method return null. This makes the button go away. Thanks.
    – Marius
    Jan 8 '16 at 14:26
7

There is no need to write plugin for class which is configured via UI Component configuration file.

There is a app/code/Magento/Customer/view/base/ui_component/customer_form.xml file with array of buttons including Create Order Buton:

 <item name="order" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\OrderButton</item>

In case this item is removed from an array the form will be rendered without "Create Order" button. In your custom module customer_form.xml file has to be prepared.

    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
    ...
    <item name="buttons" xsi:type="array">
        <item name="back" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\BackButton</item>
        <item name="delete" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\DeleteButton</item>
        <item name="invalidateToken" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\InvalidateTokenButton</item>
        <item name="resetPassword" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\ResetPasswordButton</item>
        <item name="reset" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\ResetButton</item>
        <item name="save" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\SaveButton</item>
        <item name="save_and_continue" xsi:type="string">Magento\Customer\Block\Adminhtml\Edit\SaveAndContinueButton</item>
    </item>
    ...
</argument>
4
  • 1
    Thanks. This works nicely. +1. I still orefer the plugin approach because even if by some miracle someone changes the admin theme, the button is still removed.
    – Marius
    Jan 8 '16 at 17:09
  • 1
    Marius, the OrderButton class should not be instantiated in case you do not want to see the button. With the plugin there are 2 classes will be instantiated to perform the action.
    – Max Pronko
    Jan 8 '16 at 17:59
  • 1
    Hmmm...you have a valid point...i will make up my mind on monday
    – Marius
    Jan 8 '16 at 19:22
  • not working in magento 2.0.16 Jan 3 '18 at 14:19
3

You can easily remove one of the buttons added into vendor/magento/module-customer/view/base/ui_component/customer_form.xml, declaring a new customer_form.xml file into a custom module with the following path:

app/code/VendorName/ModuleName/view/base/ui_component/customer_form.xml

and the content will be:

<?xml version="1.0" encoding="UTF-8"?>

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="buttons" xsi:type="array">
            <item name="order" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="componentDisabled" xsi:type="boolean">true</item>
                </item>
            </item>
        </item>
    </argument>
</form>

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.