I've created an add/edit form for a custom entity type, which extends Drupal\Core\Entity\ContentEntityForm
. By default this form always comes with a "Save" button, and a "Delete" button if editing. I've been asked to add a "Cancel" button as well, but can't figure out how this is supposed to be done in Drupal.
I've seen plenty of answers about using hook_form_alter()
, but nothing that is really working. My current solution is to add
$form['cancel'] = array(
'#type' => 'submit',
'#weight' => 10001,
'#submit' => array('cancel_submit'),
'#value' => t('Cancel'),
);
to the form's form()
function, where cancel_submit()
is a custom function, but that renders like which looks awful.
How can I get the two buttons to be in line with each other? Is there a way to properly add a button to the form actions?