shortcut_set_switch_access

shortcut_set_switch_access($account = NULL)

Access callback for switching the shortcut set assigned to a user account.

Parameters

object $account: (optional) The user account whose shortcuts will be switched. If not set, permissions will be checked for switching the logged-in user's own shortcut set.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

core/modules/shortcut/shortcut.module, line 82
Allows users to manage customizable lists of shortcut links.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function shortcut_set_switch_access($account = NULL) {
  $user = \Drupal::currentUser();
 
  if ($user->hasPermission('administer shortcuts')) {
    // Administrators can switch anyone's shortcut set.
    return AccessResult::allowed()->cachePerPermissions();
  }
 
  if (!$user->hasPermission('access shortcuts')) {
    // The user has no permission to use shortcuts.
    return AccessResult::neutral()->cachePerPermissions();
  }
 
  if (!$user->hasPermission('switch shortcut sets')) {
    // The user has no permission to switch anyone's shortcut set.
    return AccessResult::neutral()->cachePerPermissions();
  }
 
  // Users with the 'switch shortcut sets' permission can switch their own
  // shortcuts sets.
  if (!isset($account)) {
    return AccessResult::allowed()->cachePerPermissions();
  }
  elseif ($user->id() == $account->id()) {
    return AccessResult::allowed()->cachePerPermissions()->cachePerUser();
  }
 
  // No opinion.
  return AccessResult::neutral()->cachePerPermissions();
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.