You are here

public function ShortcutSetStorage::getDefaultSet in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/ShortcutSetStorage.php \Drupal\shortcut\ShortcutSetStorage::getDefaultSet()
  2. 10 core/modules/shortcut/src/ShortcutSetStorage.php \Drupal\shortcut\ShortcutSetStorage::getDefaultSet()

Gets the default shortcut set for a given user account.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account whose default shortcut set will be returned.

Return value

\Drupal\shortcut\ShortcutSetInterface An object representing the default shortcut set.

Overrides ShortcutSetStorageInterface::getDefaultSet

File

core/modules/shortcut/src/ShortcutSetStorage.php, line 128

Class

ShortcutSetStorage
Defines a storage for shortcut_set entities.

Namespace

Drupal\shortcut

Code

public function getDefaultSet(AccountInterface $account) {

  // Allow modules to return a default shortcut set name. Since we can only
  // have one, we allow the last module which returns a valid result to take
  // precedence. If no module returns a valid set, fall back on the site-wide
  // default, which is the lowest-numbered shortcut set.
  $suggestions = array_reverse($this->moduleHandler
    ->invokeAll('shortcut_default_set', [
    $account,
  ]));
  $suggestions[] = 'default';
  $shortcut_set = NULL;
  foreach ($suggestions as $name) {
    if ($shortcut_set = $this
      ->load($name)) {
      break;
    }
  }
  return $shortcut_set;
}