Commit e2e00fda authored by webchick's avatar webchick

Issue #2062021 by rhm50, InternetDevels: Replace user_access() calls with...

Issue #2062021 by rhm50, InternetDevels: Replace user_access() calls with ->hasPermission() in shortcut module.
parent 29777851
...@@ -23,16 +23,17 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A ...@@ -23,16 +23,17 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
switch ($operation) { switch ($operation) {
case 'create': case 'create':
case 'update': case 'update':
if (user_access('administer shortcuts', $account)) { if ($account->hasPermission('administer shortcuts')) {
return TRUE; return TRUE;
} }
if (user_access('customize shortcut links', $account)) { if ($account->hasPermission('customize shortcut links')) {
return !isset($entity) || $entity == shortcut_current_displayed_set($account); return !isset($entity) || $entity == shortcut_current_displayed_set($account);
} }
return FALSE; return FALSE;
break; break;
case 'delete': case 'delete':
if (!user_access('administer shortcuts', $account)) { if (!$account->hasPermission('administer shortcuts')) {
return FALSE; return FALSE;
} }
return $entity->id() != 'default'; return $entity->id() != 'default';
......
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
* @see shortcut_set_switch_submit() * @see shortcut_set_switch_submit()
*/ */
function shortcut_set_switch($form, &$form_state, $account = NULL) { function shortcut_set_switch($form, &$form_state, $account = NULL) {
global $user; $user = Drupal::currentUser();
if (!isset($account)) { if (!isset($account)) {
$account = $user; $account = $user;
} }
...@@ -42,7 +43,7 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) { ...@@ -42,7 +43,7 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) {
} }
// Only administrators can add shortcut sets. // Only administrators can add shortcut sets.
$add_access = user_access('administer shortcuts'); $add_access = $user->hasPermission('administer shortcuts');
if ($add_access) { if ($add_access) {
$options['new'] = t('New set'); $options['new'] = t('New set');
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Implements hook_help(). * Implements hook_help().
*/ */
function shortcut_help($path, $arg) { function shortcut_help($path, $arg) {
global $user; $user = Drupal::currentUser();
switch ($path) { switch ($path) {
case 'admin/help#shortcut': case 'admin/help#shortcut':
...@@ -32,7 +32,7 @@ function shortcut_help($path, $arg) { ...@@ -32,7 +32,7 @@ function shortcut_help($path, $arg) {
case 'admin/config/user-interface/shortcut': case 'admin/config/user-interface/shortcut':
case 'admin/config/user-interface/shortcut/%': case 'admin/config/user-interface/shortcut/%':
if (user_access('switch shortcut sets')) { if ($user->hasPermission('switch shortcut sets')) {
$output = '<p>' . t('Define which shortcut set you are using on the <a href="@shortcut-link">Shortcuts tab</a> of your account page.', array('@shortcut-link' => url("user/{$user->id()}/shortcuts"))) . '</p>'; $output = '<p>' . t('Define which shortcut set you are using on the <a href="@shortcut-link">Shortcuts tab</a> of your account page.', array('@shortcut-link' => url("user/{$user->id()}/shortcuts"))) . '</p>';
return $output; return $output;
} }
...@@ -171,12 +171,13 @@ function shortcut_admin_paths() { ...@@ -171,12 +171,13 @@ function shortcut_admin_paths() {
* otherwise. * otherwise.
*/ */
function shortcut_set_edit_access($shortcut_set = NULL) { function shortcut_set_edit_access($shortcut_set = NULL) {
$account = Drupal::currentUser();
// Sufficiently-privileged users can edit their currently displayed shortcut // Sufficiently-privileged users can edit their currently displayed shortcut
// set, but not other sets. Shortcut administrators can edit any set. // set, but not other sets. Shortcut administrators can edit any set.
if (user_access('administer shortcuts')) { if ($account->hasPermission('administer shortcuts')) {
return TRUE; return TRUE;
} }
if (user_access('customize shortcut links')) { if ($account->hasPermission('customize shortcut links')) {
return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set(); return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set();
} }
return FALSE; return FALSE;
...@@ -195,14 +196,14 @@ function shortcut_set_edit_access($shortcut_set = NULL) { ...@@ -195,14 +196,14 @@ function shortcut_set_edit_access($shortcut_set = NULL) {
* provided account, FALSE otherwise. * provided account, FALSE otherwise.
*/ */
function shortcut_set_switch_access($account = NULL) { function shortcut_set_switch_access($account = NULL) {
global $user; $user = Drupal::currentUser();
if (user_access('administer shortcuts')) { if ($user->hasPermission('administer shortcuts')) {
// Administrators can switch anyone's shortcut set. // Administrators can switch anyone's shortcut set.
return TRUE; return TRUE;
} }
if (!user_access('switch shortcut sets')) { if (!$user->hasPermission('switch shortcut sets')) {
// The user has no permission to switch anyone's shortcut set. // The user has no permission to switch anyone's shortcut set.
return FALSE; return FALSE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment