diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 2e9daac..894af46 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 a 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 way to get the #href? + $actions['delete'] = array( + '#type' => 'link', + '#title' => t('Delete'), + '#href' => $entity_uri['path'] . '/delete', + ); + } + } + return $actions; } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index efcbf0e..f9818c6 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -215,8 +215,10 @@ function testCRUDUI() { // Delete the configuration entity. $this->drupalGet("admin/structure/config_test/manage/$id/edit"); - $this->drupalPost(NULL, array(), 'Delete'); - $this->assertUrl("admin/structure/config_test/manage/$id/delete"); + // There should be two delete links - a tab and a link in the actions + // section. + $this->assertLinkByHref("admin/structure/config_test/manage/$id/delete", 1); + $this->drupalGet("admin/structure/config_test/manage/$id/delete"); $this->drupalPost(NULL, array(), 'Delete'); $this->assertUrl('admin/structure/config_test'); $this->assertResponse(200); diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 215ad81..0d32ca0 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -265,7 +265,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/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index b2603d6..3ae349f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -185,7 +185,11 @@ function testNodeTermCreationAndDeletion() { } // Delete term 1 from the term edit page. - $this->drupalPost('taxonomy/term/' . $term_objects['term1']->tid . '/edit', array(), t('Delete')); + $this->drupalGet('taxonomy/term/' . $term_objects['term1']->tid . '/edit'); + // There should be two delete links - a tab and a link in the actions + // section. + $this->assertLinkByHref('taxonomy/term/' . $term_objects['term1']->tid . '/delete', 1); + $this->drupalGet('taxonomy/term/' . $term_objects['term1']->tid . '/delete'); $this->drupalPost(NULL, NULL, t('Delete')); // Delete term 2 from the term delete page. @@ -338,7 +342,7 @@ function testTermInterface() { $this->drupalGet('taxonomy/term/' . $term->tid . '/edit/' . $this->randomName()); // Delete the term. - $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', array(), t('Delete')); + $this->drupalGet('taxonomy/term/' . $term->tid . '/delete'); $this->drupalPost(NULL, NULL, t('Delete')); // Assert that the term no longer exists. 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')) {