diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Access/SetSwitchAccessCheck.php b/core/modules/shortcut/lib/Drupal/shortcut/Access/SetSwitchAccessCheck.php index b9aea02..3eddd0c 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Access/SetSwitchAccessCheck.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/SetSwitchAccessCheck.php @@ -8,31 +8,48 @@ namespace Drupal\shortcut\Access; use Drupal\Core\Access\AccessCheckInterface; +use Drupal\Core\Access\StaticAccessCheckInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; /** * Defines a access checker for switching the shortcut set of a user account. */ -class SetSwitchAccessCheck implements AccessCheckInterface { +class SetSwitchAccessCheck implements StaticAccessCheckInterface { + + /** + * Contains the current user. + * + * @var \Drupal\Core\Session\AccountInterface + */ + protected $account; + + /** + * Constructs a new SetSwitchAccessCheck. + * + * @param \Drupal\Core\Session\AccountInterface $account + */ + public function __construct($account) { + $this->account = $account; + } /** * {@inheritdoc} */ - public function applies(Route $route) { - return array_key_exists('_shortcut_set_switch', $route->getRequirements()); + public function appliesTo() { + // TODO: Implement appliesTo() method. + return array('_shortcut_set_switch'); } /** * {@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 = $account->hasPermission('switch shortcut sets') && $user->id() == $account->id(); + $access = $this->account->hasPermission('switch shortcut sets') && $user->id() == $this->account->id(); return $access ? static::ALLOW : static::DENY; } diff --git a/core/modules/shortcut/shortcut.services.yml b/core/modules/shortcut/shortcut.services.yml index c306354..7d8301a 100644 --- a/core/modules/shortcut/shortcut.services.yml +++ b/core/modules/shortcut/shortcut.services.yml @@ -5,5 +5,6 @@ services: - { name: access_check } access_check.shortcut.switch: class: Drupal\shortcut\Access\SetSwitchAccessCheck + arguments: ['@current_user'] tags: - { name: access_check }