You are here

function shortcut_current_displayed_set in Drupal 9

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

Returns the current displayed shortcut set for the provided user account.

Parameters

$account: (optional) The user account whose shortcuts will be returned. Defaults to the currently logged-in user.

Return value

An object representing the shortcut set that should be displayed to the current user. If the user does not have an explicit shortcut set defined, the default set is returned.

13 calls to shortcut_current_displayed_set()
MigrateShortcutSetUsersTest::testShortcutSetUsersMigration in core/modules/shortcut/tests/src/Kernel/Migrate/d7/MigrateShortcutSetUsersTest.php
Tests the shortcut set migration.
ShortcutLazyBuilders::lazyLinks in core/modules/shortcut/src/ShortcutLazyBuilders.php
#lazy_builder callback; builds shortcut toolbar links.
ShortcutsBlock::build in core/modules/shortcut/src/Plugin/Block/ShortcutsBlock.php
Builds and returns the renderable array for this block plugin.
ShortcutSetsTest::testShortcutSetAssign in core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
Tests switching another user's shortcut set.
ShortcutSetsTest::testShortcutSetSwitchCreate in core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
Tests switching a user's shortcut set and creating one at the same time.

... See full list

1 string reference to 'shortcut_current_displayed_set'
ShortcutSetStorage::assignUser in core/modules/shortcut/src/ShortcutSetStorage.php
Assigns a user to a particular shortcut set.

File

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

Code

function shortcut_current_displayed_set($account = NULL) {
  $shortcut_sets =& drupal_static(__FUNCTION__, []);
  $user = \Drupal::currentUser();
  if (!isset($account)) {
    $account = $user;
  }

  // Try to return a shortcut set from the static cache.
  if (isset($shortcut_sets[$account
    ->id()])) {
    return $shortcut_sets[$account
      ->id()];
  }

  // If none was found, try to find a shortcut set that is explicitly assigned
  // to this user.
  $shortcut_set_name = \Drupal::entityTypeManager()
    ->getStorage('shortcut_set')
    ->getAssignedToUser($account);
  if ($shortcut_set_name) {
    $shortcut_set = ShortcutSet::load($shortcut_set_name);
  }
  else {
    $shortcut_set = shortcut_default_set($account);
  }
  $shortcut_sets[$account
    ->id()] = $shortcut_set;
  return $shortcut_set;
}