Hi guys today I had a little problem. It had to remove one of the magento 2 default buttons like you probably have seen. I needed to remove the save button.It is a read-only module so there is no need for a save button.
I looked at all possible places and could not find the answer so I tried to solve it on my own way and I came up with a solution.
In order to remove any default button that magento generates for you. You first need to check what is the button id. You can do it by simply going in the inspect element mode of your browser, which will give you something like this.
Now that you have the button’s ID you can delete it. I’ll show you how to do that.
Now you just need to follow these simple steps:
- Find the php file which is responsible for generating your layout.In my case it is located in /Module/Controller/Block/Adminhtml/Controller/yourphpfile.php
- Make sure that your class is extending the Container class from the Magento\Backend\Block\Widget\Form\Container namespace. Because the buttonList->remove function is the Container classes function
- Since magento does not allow the __construct function to be changed the only solution for me was to change it in the _prepareLayout function. You can do it just by placing this function call in the _prepareLayout function of your php file $this->buttonList->remove(‘save’);
With this your button should be successfully removed.