I am working on the custom extension and I need delete button in the custom form at the backend. When I edit a record, there should be delete button above with other buttons like Back, Reset and Save and continue edit. Please see the screenshot to get more idea. Can someone guide me for it?
1 Answer
Add below code in app\code\Vendor\ModuleName\Block\Adminhtml\Module\Edit.php in _construct()
protected function _construct(){
$this->addButton(
'delete',
[
'label' => __('Delete'),
'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to do this?'))
. ','
. json_encode($this->getDeleteUrl()
)
. ')',
'class' => 'scalable delete',
'level' => -1
]
);
}
Below will be your delete action.
/**
* @param array $args
* @return string
*/
public function getDeleteUrl(array $args = [])
{
$params = array_merge($this->getDefaultUrlParams(), $args);
return $this->getUrl('module/*/delete', $params);
}
-
3I have done minor change to make it work, public function getDeleteUrl(array $args = []) { return $this->getUrl('*/*/delete', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']); }Gaurav Jain– Gaurav Jain2016-06-22 11:35:47 +00:00Commented Jun 22, 2016 at 11:35
-
Hello @Ajay, I have also added delete button from your code, but it is also appearing for new form as well, so what condition will add to hide from new form?Vinaya Maheshwari– Vinaya Maheshwari2017-07-07 09:39:10 +00:00Commented Jul 7, 2017 at 9:39

Edit.phpblock file?