shortcut_current_displayed_set

shortcut_current_displayed_set($account = NULL)

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.

File

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

Code

function shortcut_current_displayed_set($account = NULL) {
  $shortcut_sets = &drupal_static(__FUNCTION__, array());
  $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::entityManager()
    ->getStorage('shortcut_set')
    ->getAssignedToUser($account);
  if ($shortcut_set_name) {
    $shortcut_set = ShortcutSet::load($shortcut_set_name);
  }
  // Otherwise, use the default set.
  else {
    $shortcut_set = shortcut_default_set($account);
  }

  $shortcut_sets[$account->id()] = $shortcut_set;
  return $shortcut_set;
}
doc_Drupal
2016-10-29 09:43:00
Comments
Leave a Comment

Please login to continue.