diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index b43c11255f2e37c662450d80d3853d8e63d26a32..b0929143629ff0c076df3619abb8e1436bfd4e08 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -129,6 +129,9 @@ protected function processAccessHookResults(array $access) { * could not be determined. */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { + if ($operation == 'delete' && $entity->isNew()) { + return FALSE; + } if ($admin_permission = $this->entityType->getAdminPermission()) { return $account->hasPermission($admin_permission); } diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index c80daa42586909442a320b4078649043374d1f99..9f5969420624502158afa8cb9828b8fdc5edeee9 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -168,11 +168,7 @@ public function processForm($element, $form_state, $form) { 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->entity->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']; @@ -230,6 +226,7 @@ protected function actions(array $form, array &$form_state) { $actions['delete'] = array( '#type' => 'link', '#title' => $this->t('Delete'), + '#access' => $this->entity->access('delete'), '#attributes' => array( 'class' => array('button', 'button--danger'), ), diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Message.php b/core/modules/contact/lib/Drupal/contact/Entity/Message.php index ea7eaa85ccab50f18d6d9f91ad42a743a4ad8725..f2c05fc9d5ed638498c43bbfc685106dd35eaabb 100644 --- a/core/modules/contact/lib/Drupal/contact/Entity/Message.php +++ b/core/modules/contact/lib/Drupal/contact/Entity/Message.php @@ -44,6 +44,13 @@ public function id() { return NULL; } + /** + * {@inheritdoc} + */ + public function uuid() { + return NULL; + } + /** * {@inheritdoc} */ diff --git a/core/modules/contact/lib/Drupal/contact/MessageForm.php b/core/modules/contact/lib/Drupal/contact/MessageForm.php index 4519db7a8cfd60c2949eaab123a6de73512f5faf..401291ede55e2e2007d861e5de259c27cdd85b4a 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageForm.php +++ b/core/modules/contact/lib/Drupal/contact/MessageForm.php @@ -146,7 +146,6 @@ public function form(array $form, array &$form_state) { public function actions(array $form, array &$form_state) { $elements = parent::actions($form, $form_state); $elements['submit']['#value'] = t('Send message'); - $elements['delete']['#access'] = FALSE; $elements['preview'] = array( '#value' => t('Preview'), '#validate' => array( diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatFormBase.php b/core/modules/filter/lib/Drupal/filter/FilterFormatFormBase.php index 28d2758da9b3ad5b1daa27eb0ebd39007094c4cb..fd9520d456b1b9d3388ca7c46377068d2794be0b 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatFormBase.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatFormBase.php @@ -268,7 +268,6 @@ public function submit(array $form, array &$form_state) { protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = t('Save configuration'); - unset($actions['delete']); return $actions; } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkForm.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkForm.php index 422906fccbf0b708227548be6aac55a0e9c6e108..b4c6904f22b3dfe5803037521e4a6f5de066f03e 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkForm.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkForm.php @@ -195,8 +195,6 @@ public function form(array $form, array &$form_state) { protected function actions(array $form, array &$form_state) { $element = parent::actions($form, $form_state); $element['submit']['#button_type'] = 'primary'; - $element['delete']['#access'] = $this->entity->access('delete'); - return $element; } diff --git a/core/modules/menu_ui/lib/Drupal/menu_ui/MenuForm.php b/core/modules/menu_ui/lib/Drupal/menu_ui/MenuForm.php index aa8a51a8a48088e8e76f28e1d09e54bb0f8c3e6c..a796f66174c8d997ce49143e0ca02a577f6b072a 100644 --- a/core/modules/menu_ui/lib/Drupal/menu_ui/MenuForm.php +++ b/core/modules/menu_ui/lib/Drupal/menu_ui/MenuForm.php @@ -178,8 +178,6 @@ public function menuNameExists($value) { protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); - $actions['delete']['#access'] = !$this->entity->isNew() && $this->entity->access('delete'); - // Add the language configuration submit handler. This is needed because the // submit button has custom submit handlers. if ($this->moduleHandler->moduleExists('language')) { diff --git a/core/modules/node/lib/Drupal/node/NodeTypeForm.php b/core/modules/node/lib/Drupal/node/NodeTypeForm.php index 0875c8046f901b66228db9e095dd855030ccc626..4d87e03760c7fd854b4caceba383a9b1134f4d8a 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeForm.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeForm.php @@ -163,7 +163,6 @@ protected function actions(array $form, array &$form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = t('Save content type'); $actions['delete']['#value'] = t('Delete content type'); - $actions['delete']['#access'] = $this->entity->access('delete'); return $actions; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index 6cfc32f2334b216d329a7121c7edc6b314776b1b..4f3defa21cd946dbb458fa86f6565c5442ee11d5 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -193,9 +193,13 @@ function testNodeTypeDeletion() { $this->assertText(t('This action cannot be undone.'), 'The node type deletion confirmation form is available.'); // Test that forum node type could not be deleted while forum active. $this->container->get('module_handler')->install(array('forum')); + $this->drupalGet('admin/structure/types/manage/forum'); + $this->assertNoLink(t('Delete')); $this->drupalGet('admin/structure/types/manage/forum/delete'); $this->assertResponse(403); $this->container->get('module_handler')->uninstall(array('forum')); + $this->drupalGet('admin/structure/types/manage/forum'); + $this->assertLink(t('Delete')); $this->drupalGet('admin/structure/types/manage/forum/delete'); $this->assertResponse(200); } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php b/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php index 43fed9c6d5628d460bb693a10676e53946e74434..45e5cd4033b8ba8d32ec2e536b05d9bf31ffcaae 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchPageFormBase.php @@ -181,15 +181,4 @@ public function save(array $form, array &$form_state) { $form_state['redirect_route']['route_name'] = 'search.settings'; } - /** - * {@inheritdoc} - */ - protected function actions(array $form, array &$form_state) { - $actions = parent::actions($form, $form_state); - if ($this->entity->isDefaultSearch()) { - unset($actions['delete']); - } - return $actions; - } - } diff --git a/core/modules/shortcut/src/ShortcutSetForm.php b/core/modules/shortcut/src/ShortcutSetForm.php index c35b72d1c3d0abd4b67f46ce6d2c9987a0ee2290..3dd6282947562ae385e3a386629585057b950286 100644 --- a/core/modules/shortcut/src/ShortcutSetForm.php +++ b/core/modules/shortcut/src/ShortcutSetForm.php @@ -47,16 +47,6 @@ public function form(array $form, array &$form_state) { return $form; } - /** - * {@inheritdoc} - */ - protected function actions(array $form, array &$form_state) { - // Disable delete of default shortcut set. - $actions = parent::actions($form, $form_state); - $actions['delete']['#access'] = $this->entity->access('delete'); - return $actions; - } - /** * {@inheritdoc} */ diff --git a/core/modules/user/lib/Drupal/user/RoleForm.php b/core/modules/user/lib/Drupal/user/RoleForm.php index 902fc041d8b814b8327a0d2b155aad7b5c3e390f..2bed647ac6e7b3ad499eff428557fad9cc376c20 100644 --- a/core/modules/user/lib/Drupal/user/RoleForm.php +++ b/core/modules/user/lib/Drupal/user/RoleForm.php @@ -48,16 +48,6 @@ public function form(array $form, array &$form_state) { return parent::form($form, $form_state, $entity); } - /** - * {@inheritdoc} - */ - protected function actions(array $form, array &$form_state) { - $actions = parent::actions($form, $form_state); - // Disable delete of new and built-in roles. - $actions['delete']['#access'] = !$this->entity->isNew() && !in_array($this->entity->id(), array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID)); - return $actions; - } - /** * {@inheritdoc} */