diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 2e9daac..024a099 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -89,11 +89,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { protected function actionsElement(array $form, array &$form_state) { $element = $this->actions($form, $form_state); - // We cannot delete an entity that has not been created yet. - if ($this->getEntity($form_state)->isNew()) { - unset($element['delete']); - } - elseif (isset($element['delete'])) { + if (isset($element['delete'])) { // Move the delete action as last one, unless weights are explicitly // provided. $delete = $element['delete']; @@ -120,7 +116,9 @@ protected function actionsElement(array $form, array &$form_state) { * Returns an array of supported actions for the current entity form. */ protected function actions(array $form, array &$form_state) { - return array( + $entity = $this->getEntity($form_state); + $entity_uri = $entity->uri(); + $actions = array( // @todo Rename the action key from submit to save. 'submit' => array( '#value' => t('Save'), @@ -132,16 +130,32 @@ protected function actions(array $form, array &$form_state) { array($this, 'save'), ), ), - 'delete' => array( - '#value' => t('Delete'), - // No need to validate the form when deleting the entity. - '#submit' => array( - array($this, 'delete'), - ), - ), // @todo Consider introducing a 'preview' action here, since it is used by // many entity types. ); + $entity = $this->getEntity($form_state); + $entity_uri = $entity->uri(); + if (!$entity->isNew()) { + if (empty($entity_uri['path'])) { + // For entities without URI we have to use a submit button + $actions['delete'] = array( + '#value' => t('Delete'), + '#submit' => array( + array($this, 'delete'), + ), + ); + } + else { + // For entities with a URI we provide a link to the delete form. + // @todo Is this the proper why to get the #href??? + $actions['delete'] = array( + '#type' => 'link', + '#title' => t('Delete'), + '#href' => $entity_uri['path'] . '/delete', + ); + } + } + return $actions; } /** diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 563a00f..48ba0a2 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -264,7 +264,9 @@ protected function actions(array $form, array &$form_state) { ); $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])); - $element['delete']['#access'] = node_access('delete', $node); + if (isset($element['delete'])) { + $element['delete']['#access'] = node_access('delete', $node); + } return $element; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index c26251e..2220c29 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -91,7 +91,9 @@ protected function actions(array $form, array &$form_state) { // If we are displaying the delete confirmation skip the regular actions. if (empty($form_state['confirm_delete'])) { $actions = parent::actions($form, $form_state); - array_unshift($actions['delete']['#submit'], array($this, 'submit')); + if (isset($actions['delete'])) { + array_unshift($actions['delete']['#submit'], array($this, 'submit')); + } // Add the language configuration submit handler. This is needed because // the submit button has custom submit handlers. if (module_exists('language')) {