4f33b0b555737fb5b15545047313e624e577f76d
[yaffs-website] / web / core / modules / shortcut / src / Controller / ShortcutController.php
1 <?php
2
3 namespace Drupal\shortcut\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\shortcut\ShortcutSetInterface;
7 use Drupal\shortcut\ShortcutInterface;
8
9 /**
10  * Provides route responses for taxonomy.module.
11  */
12 class ShortcutController extends ControllerBase {
13
14   /**
15    * Returns a form to add a new shortcut to a given set.
16    *
17    * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
18    *   The shortcut set this shortcut will be added to.
19    *
20    * @return array
21    *   The shortcut add form.
22    */
23   public function addForm(ShortcutSetInterface $shortcut_set) {
24     $shortcut = $this->entityManager()->getStorage('shortcut')->create(['shortcut_set' => $shortcut_set->id()]);
25     return $this->entityFormBuilder()->getForm($shortcut, 'add');
26   }
27
28   /**
29    * Deletes the selected shortcut.
30    *
31    * @param \Drupal\shortcut\ShortcutInterface $shortcut
32    *   The shortcut to delete.
33    *
34    * @return \Symfony\Component\HttpFoundation\RedirectResponse
35    *   A redirect to the previous location or the front page when destination
36    *   is not set.
37    */
38   public function deleteShortcutLinkInline(ShortcutInterface $shortcut) {
39     $label = $shortcut->label();
40
41     try {
42       $shortcut->delete();
43       drupal_set_message($this->t('The shortcut %title has been deleted.', ['%title' => $label]));
44     }
45     catch (\Exception $e) {
46       drupal_set_message($this->t('Unable to delete the shortcut for %title.', ['%title' => $label]), 'error');
47     }
48
49     return $this->redirect('<front>');
50   }
51
52 }