diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Access/SwitchShortcutSetAccessCheck.php b/core/modules/shortcut/lib/Drupal/shortcut/Access/SwitchShortcutSetAccessCheck.php index 02dff71..ed842b4 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Access/SwitchShortcutSetAccessCheck.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/SwitchShortcutSetAccessCheck.php @@ -18,23 +18,6 @@ class SwitchShortcutSetAccessCheck implements StaticAccessCheckInterface { /** - * Contains the current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $account; - - /** - * Constructs a new SwitchShortcutSetAccessCheck. - * - * @param \Drupal\Core\Session\AccountInterface $account - * The current user. - */ - public function __construct($account) { - $this->account = $account; - } - - /** * {@inheritdoc} */ public function appliesTo() { @@ -45,11 +28,12 @@ public function appliesTo() { * {@inheritdoc} */ public function access(Route $route, Request $request) { + $account = $request->attributes->get('_account') ?: $GLOBALS['user']; $user = $request->attributes->get('user'); // Users with the 'switch shortcut sets' permission can switch their own // shortcuts sets. - $access = $this->account->hasPermission('switch shortcut sets') && $user->id() == $this->account->id(); + $access = $account->hasPermission('switch shortcut sets') && $user->id() == $account->id(); return $access ? static::ALLOW : static::DENY; } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/SwitchShortcutSet.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/SwitchShortcutSet.php index 44eb1c5..0bd747b 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/SwitchShortcutSet.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/SwitchShortcutSet.php @@ -10,10 +10,13 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\Query\QueryFactory; +use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormInterface; use Drupal\Component\Utility\String; use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\shortcut\ShortcutSetStorageControllerInterface; use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -38,23 +41,23 @@ class SwitchShortcutSet extends FormBase implements ContainerInjectionInterface, protected $storageController; /** - * The url generator. + * The entity query factory * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Entity\Query\QueryFactory */ - protected $urlGenerator; + protected $queryFactory; /** * Constructs a SwitchShortcutSet object. * - * @param \Drupal\Core\Entity\EntityManager $entity_manager - * The entity manager. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The url generator. + * @param \Drupal\shortcut\ShortcutSetStorageControllerInterface $shortcut_set_storage_controller + * The shortcut storage controller. + * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory + * The entity query factory. */ - public function __construct(EntityManager $entity_manager, UrlGeneratorInterface $url_generator) { - $this->storageController = $entity_manager->getStorageController('shortcut_set'); - $this->urlGenerator = $url_generator; + public function __construct(ShortcutSetStorageControllerInterface $shortcut_set_storage_controller, QueryFactory $query_factory) { + $this->storageController = $shortcut_set_storage_controller; + $this->queryFactory = $query_factory; } /** @@ -62,8 +65,8 @@ public function __construct(EntityManager $entity_manager, UrlGeneratorInterface */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), - $container->get('url_generator') + $container->get('entity.manager')->getStorageController('shortcut_set'), + $container->get('entity.query') ); } @@ -78,7 +81,7 @@ public function getFormID() { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state, UserInterface $user = NULL) { - $account = $this->getRequest()->attributes->get('_account'); + $account = $this->getCurrentUser(); $this->user = $user; @@ -173,7 +176,7 @@ public function validateForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $account = $this->getRequest()->attributes->get('_account'); + $account = $this->getCurrentUser(); $account_is_user = $this->user->id() == $account->id(); if ($form_state['values']['set'] == 'new') { @@ -188,7 +191,8 @@ public function submitForm(array &$form, array &$form_state) { $replacements = array( '%user' => $this->user->label(), '%set_name' => $set->label(), - '@switch-url' => $this->urlGenerator->generateFromPath($this->request->attributes->get('_system_path')), + // @todo Convert once https://drupal.org/node/2073813 is in. + '@switch-url' => \Drupal::urlGenerator()->generateFromPath($this->getRequest()->attributes->get('_system_path')), ); if ($account_is_user) { // Only administrators can create new shortcut sets, so we know they have @@ -224,8 +228,10 @@ public function submitForm(array &$form, array &$form_state) { * TRUE if the shortcut set exists, FALSE otherwise. */ public function exists($id) { - $sets = $this->storageController->load($id); - return !empty($sets); + return (bool) $this->queryFactory + ->get('shortcut_set') + ->condition('id', $id) + ->execute(); } } diff --git a/core/modules/shortcut/shortcut.services.yml b/core/modules/shortcut/shortcut.services.yml index 94ed2c1..f2916f6 100644 --- a/core/modules/shortcut/shortcut.services.yml +++ b/core/modules/shortcut/shortcut.services.yml @@ -5,6 +5,5 @@ services: - { name: access_check } access_check.shortcut.switch: class: Drupal\shortcut\Access\SwitchShortcutSetAccessCheck - arguments: ['@current_user'] tags: - { name: access_check }