Issue #2062021 by rhm50, InternetDevels: Replace user_access() calls with ->hasPermission() in shortcut module.
parent
297778513d
commit
e2e00fdae4
|
@ -23,16 +23,17 @@ class ShortcutSetAccessController extends EntityAccessController {
|
|||
switch ($operation) {
|
||||
case 'create':
|
||||
case 'update':
|
||||
if (user_access('administer shortcuts', $account)) {
|
||||
if ($account->hasPermission('administer shortcuts')) {
|
||||
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 FALSE;
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
if (!user_access('administer shortcuts', $account)) {
|
||||
if (!$account->hasPermission('administer shortcuts')) {
|
||||
return FALSE;
|
||||
}
|
||||
return $entity->id() != 'default';
|
||||
|
|
|
@ -27,7 +27,8 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|||
* @see shortcut_set_switch_submit()
|
||||
*/
|
||||
function shortcut_set_switch($form, &$form_state, $account = NULL) {
|
||||
global $user;
|
||||
$user = Drupal::currentUser();
|
||||
|
||||
if (!isset($account)) {
|
||||
$account = $user;
|
||||
}
|
||||
|
@ -42,7 +43,7 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) {
|
|||
}
|
||||
|
||||
// Only administrators can add shortcut sets.
|
||||
$add_access = user_access('administer shortcuts');
|
||||
$add_access = $user->hasPermission('administer shortcuts');
|
||||
if ($add_access) {
|
||||
$options['new'] = t('New set');
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
* Implements hook_help().
|
||||
*/
|
||||
function shortcut_help($path, $arg) {
|
||||
global $user;
|
||||
$user = Drupal::currentUser();
|
||||
|
||||
switch ($path) {
|
||||
case 'admin/help#shortcut':
|
||||
|
@ -32,7 +32,7 @@ function shortcut_help($path, $arg) {
|
|||
|
||||
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>';
|
||||
return $output;
|
||||
}
|
||||
|
@ -171,12 +171,13 @@ function shortcut_admin_paths() {
|
|||
* otherwise.
|
||||
*/
|
||||
function shortcut_set_edit_access($shortcut_set = NULL) {
|
||||
$account = Drupal::currentUser();
|
||||
// Sufficiently-privileged users can edit their currently displayed shortcut
|
||||
// set, but not other sets. Shortcut administrators can edit any set.
|
||||
if (user_access('administer shortcuts')) {
|
||||
if ($account->hasPermission('administer shortcuts')) {
|
||||
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 FALSE;
|
||||
|
@ -195,14 +196,14 @@ function shortcut_set_edit_access($shortcut_set = NULL) {
|
|||
* provided account, FALSE otherwise.
|
||||
*/
|
||||
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.
|
||||
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.
|
||||
return FALSE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue