1

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?

enter image description here

1
  • can you show the code from your Edit.php block file? – Marius Jun 22 '16 at 11:09
6

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);
}
2
  • 3
    I 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 Jun 22 '16 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 Jul 7 '17 at 9:39

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.