diff -u b/core/modules/shortcut/src/Form/SwitchShortcutSet.php b/core/modules/shortcut/src/Form/SwitchShortcutSet.php --- b/core/modules/shortcut/src/Form/SwitchShortcutSet.php +++ b/core/modules/shortcut/src/Form/SwitchShortcutSet.php @@ -10,6 +10,8 @@ use Drupal\Component\Utility\String; use Drupal\Core\Access\AccessInterface; use Drupal\Core\Form\FormBase; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\shortcut\Entity\ShortcutSet; use Drupal\shortcut\ShortcutSetStorageInterface; use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -27,20 +29,30 @@ protected $user; /** - * The shortcut storage controller. + * The shortcut set storage. * * @var \Drupal\shortcut\ShortcutSetStorageInterface */ - protected $storageController; + protected $shortcutSetStorage; /** - * Constructs a SwitchShortcutSet object. + * The current route match. * - * @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage_controller - * The shortcut set storage controller. + * @var \Drupal\Core\Routing\RouteMatchInterface */ - public function __construct(ShortcutSetStorageInterface $shortcut_set_storage_controller) { - $this->storageController = $shortcut_set_storage_controller; + protected $routeMatch; + + /** + * Constructs a SwitchShortcutSet object. + * + * @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage + * The shortcut set storage. + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * The current route match. + */ + public function __construct(ShortcutSetStorageInterface $shortcut_set_storage, RouteMatchInterface $route_match) { + $this->shortcutSetStorage = $shortcut_set_storage; + $this->routeMatch = $route_match; } /** @@ -48,7 +60,8 @@ */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorage('shortcut_set') + $container->get('entity.manager')->getStorage('shortcut_set'), + $container->get('current_route_match') ); } @@ -68,9 +81,9 @@ $this->user = $user; // Prepare the list of shortcut sets. - $options = array_map(function ($set) { + $options = array_map(function (ShortcutSet $set) { return String::checkPlain($set->label()); - }, $this->storageController->loadMultiple()); + }, $this->shortcutSetStorage->loadMultiple()); $current_set = shortcut_current_displayed_set($this->user); @@ -114,7 +127,7 @@ ); if (!$account_is_user) { - $default_set = $this->storageController->getDefaultSet($this->user); + $default_set = $this->shortcutSetStorage->getDefaultSet($this->user); $form['new']['#description'] = $this->t('The new set is created by copying items from the %default set.', array('%default' => $default_set->label())); } @@ -148,7 +161,7 @@ * TRUE if the shortcut set exists, FALSE otherwise. */ public function exists($id) { - return (bool) $this->storageController->getQuery() + return (bool) $this->shortcutSetStorage->getQuery() ->condition('id', $id) ->execute(); } @@ -178,17 +191,16 @@ $account_is_user = $this->user->id() == $account->id(); if ($form_state['values']['set'] == 'new') { // Save a new shortcut set with links copied from the user's default set. - $default_set = $this->storageController->getDefaultSet($this->user); - $set = $this->storageController->create(array( + /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ + $set = $this->shortcutSetStorage->create(array( 'id' => $form_state['values']['id'], 'label' => $form_state['values']['label'], - 'links' => $default_set->getShortcuts(), )); $set->save(); $replacements = array( '%user' => $this->user->label(), '%set_name' => $set->label(), - '@switch-url' => $this->url($this->getRequest()->attributes->get('_system_path')), + '@switch-url' => $this->url($this->routeMatch->getRouteName(), array('user' => $this->user->id())), ); if ($account_is_user) { // Only administrators can create new shortcut sets, so we know they have @@ -207,7 +219,8 @@ } else { // Switch to a different shortcut set. - $set = $this->storageController->load($form_state['values']['set']); + /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ + $set = $this->shortcutSetStorage->load($form_state['values']['set']); $replacements = array( '%user' => $this->user->label(), '%set_name' => $set->label(), @@ -216,7 +229,7 @@ } // Assign the shortcut set to the provided user account. - $this->storageController->assignUser($set, $this->user); + $this->shortcutSetStorage->assignUser($set, $this->user); } /**