Khanh Hoang - Kenn
Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.
In Drupal 8 delete buttons switched to links instead of submit buttons.
Main reasons for this switch:
<?php function myform($form, &$form_state) { $form = array(); // ... // The rest of form declaration. // ... $form['actions']['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), '#submit' => array('myform_delete_submit'), ); return $form; } function myform_delete_submit($form, &$form_state) { $form_state['redirect'] = 'my/path/delete'; } ?>
<?php use Drupal\Core\Form\FormBase; class MyForm extends FormBase { public function buildForm(array $form, array &$form_state) { $form = array(); // ... // The rest of form declaration. // ... $form['actions']['delete'] = array( '#type' => 'link', '#title' => $this->t('Delete'), '#attributes' => array( 'class' => array('button', 'button--danger'), ), '#route_name' => 'my.delete_route', ); return parent::buildForm($form, $form_state); } } ?>