diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index be1d027d8a863a20ca412260b4aad964b4b36fb8..9dc7d5a667d7edc2f95d956ad2ba57d8456ccd9e 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -359,7 +359,7 @@ function shortcut_preprocess_page(&$variables) { else { $query['id'] = $shortcut_id; $link_text = shortcut_set_switch_access() ? t('Remove from %shortcut_set shortcuts', array('%shortcut_set' => $shortcut_set->label())) : t('Remove from shortcuts'); - $route_name = 'entity.shortcut.delete_form'; + $route_name = 'entity.shortcut.link_delete_inline'; $route_parameters = array('shortcut' => $shortcut_id); } diff --git a/core/modules/shortcut/shortcut.routing.yml b/core/modules/shortcut/shortcut.routing.yml index 90752cd17f29ab6a98620a7671b5dcb72e1a7930..6a892bd72082780a3f72e80f7b2eeed7082fd339 100644 --- a/core/modules/shortcut/shortcut.routing.yml +++ b/core/modules/shortcut/shortcut.routing.yml @@ -62,6 +62,14 @@ entity.shortcut.canonical: requirements: _entity_access: 'shortcut.update' +entity.shortcut.link_delete_inline: + path: '/admin/config/user-interface/shortcut/link/{shortcut}/delete-inline' + defaults: + _controller: 'Drupal\shortcut\Controller\ShortcutController::deleteShortcutLinkInline' + requirements: + _entity_access: 'shortcut.delete' + _csrf_token: 'TRUE' + entity.shortcut.delete_form: path: '/admin/config/user-interface/shortcut/link/{shortcut}/delete' defaults: diff --git a/core/modules/shortcut/src/Controller/ShortcutController.php b/core/modules/shortcut/src/Controller/ShortcutController.php index 943caa0cd59b2231cc6a36d2c9c512b0dbded6d0..85371dee05ecf84b6466141862ae4d564cc2fbc8 100644 --- a/core/modules/shortcut/src/Controller/ShortcutController.php +++ b/core/modules/shortcut/src/Controller/ShortcutController.php @@ -9,6 +9,8 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\shortcut\ShortcutSetInterface; +use Drupal\shortcut\ShortcutInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides route responses for taxonomy.module. @@ -30,4 +32,28 @@ public function addForm(ShortcutSetInterface $shortcut_set) { return $this->entityFormBuilder()->getForm($shortcut, 'add'); } + /** + * Deletes the selected shortcut. + * + * @param \Drupal\shortcut\ShortcutInterface $shortcut + * The shortcut to delete. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * A redirect to the previous location or the front page when destination + * is not set. + */ + public function deleteShortcutLinkInline(ShortcutInterface $shortcut) { + $label = $shortcut->label(); + + try { + $shortcut->delete(); + drupal_set_message($this->t('The shortcut %title has been deleted.', array('%title' => $label))); + } + catch (\Exception $e) { + drupal_set_message($this->t('Unable to delete the shortcut for %title.', array('%title' => $label))); + } + + return $this->redirect(''); + } + } diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index 85c7253027328a2bc5ac30357ac57f7a0529ce90..2b4c73172ce1388cad1aed11fdb800bcbd6e1db5 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -118,7 +118,6 @@ public function testShortcutQuickLink() { // Test the "Remove from shortcuts" link. $this->clickLink('Cron'); $this->clickLink('Remove from Default shortcuts'); - $this->drupalPostForm(NULL, array(), 'Delete'); $this->assertText('The shortcut Cron has been deleted.'); $this->assertNoLink('Cron', 'Shortcut link removed from page');