You are here

function shortcut_set_edit_access in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/shortcut/shortcut.module \shortcut_set_edit_access()
  2. 7 modules/shortcut/shortcut.module \shortcut_set_edit_access()
  3. 9 core/modules/shortcut/shortcut.module \shortcut_set_edit_access()

Access callback for editing a shortcut set.

Parameters

Drupal\shortcut\ShortcutSetInterface $shortcut_set: (optional) The shortcut set to be edited. If not set, the current user's shortcut set will be used.

Return value

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

4 calls to shortcut_set_edit_access()
ShortcutAccessControlHandler::checkAccess in core/modules/shortcut/src/ShortcutAccessControlHandler.php
Performs access checks.
ShortcutAccessControlHandler::checkCreateAccess in core/modules/shortcut/src/ShortcutAccessControlHandler.php
Performs create access checks.
ShortcutLazyBuilders::lazyLinks in core/modules/shortcut/src/ShortcutLazyBuilders.php
#lazy_builder callback; builds shortcut toolbar links.
shortcut_preprocess_page_title in core/modules/shortcut/shortcut.module
Implements hook_preprocess_HOOK() for page title templates.
3 string references to 'shortcut_set_edit_access'
drupal7.php in core/modules/tracker/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/rdf/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.
drupal7.php in core/modules/migrate_drupal/tests/fixtures/drupal7.php
A database agnostic dump for testing purposes.

File

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

Code

function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) {
  $account = \Drupal::currentUser();

  // Shortcut administrators can edit any set.
  if ($account
    ->hasPermission('administer shortcuts')) {
    return AccessResult::allowed()
      ->cachePerPermissions();
  }

  // Sufficiently-privileged users can edit their currently displayed shortcut
  // set, but not other sets. They must also be able to access shortcuts.
  $may_edit_current_shortcut_set = $account
    ->hasPermission('customize shortcut links') && (!isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set()) && $account
    ->hasPermission('access shortcuts');
  $result = AccessResult::allowedIf($may_edit_current_shortcut_set)
    ->cachePerPermissions();
  if (!$result
    ->isAllowed()) {
    $result
      ->setReason("The shortcut set must be the currently displayed set for the user and the user must have 'access shortcuts' AND 'customize shortcut links' permissions.");
  }
  return $result;
}