Verified Commit 148e1c90 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3436892 by plopesc, smustgrave: Remove deprecated code from shortcut module

parent 4fac2d4b
Loading
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -442,11 +442,6 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
 *   unit tests with a clean environment.
 */
function drupal_static_reset($name = NULL) {
  switch ($name) {
    case 'shortcut_current_displayed_set':
      @trigger_error("Calling " . __FUNCTION__ . "() with 'shortcut_current_displayed_set' as an argument is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement for this usage. See https://www.drupal.org/node/3427050", E_USER_DEPRECATED);
      break;
  }
  drupal_static($name, NULL, TRUE);
}

+0 −67
Original line number Diff line number Diff line
@@ -121,73 +121,6 @@ function shortcut_set_switch_access($account = NULL) {
  return AccessResult::neutral()->cachePerPermissions();
}

/**
 * Returns the current displayed shortcut set for the provided user account.
 *
 * @param $account
 *   (optional) The user account whose shortcuts will be returned. Defaults to
 *   the currently logged-in user.
 *
 * @return \Drupal\shortcut\ShortcutSetInterface
 *   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.
 *
 * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
 * \Drupal\shortcut\ShortcutSetStorageInterface::getDisplayedToUser()
 * instead.
 *
 * @see https://www.drupal.org/node/3427050
 */
function shortcut_current_displayed_set($account = NULL) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\shortcut\ShortcutSetStorageInterface::getDisplayedToUser() instead. See https://www.drupal.org/node/3427050', E_USER_DEPRECATED);
  $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 = \Drupal::entityTypeManager()
    ->getStorage('shortcut_set')
    ->getDisplayedToUser($account);

  $shortcut_sets[$account->id()] = $shortcut_set;
  return $shortcut_set;
}

/**
 * Returns the default shortcut set for a given user account.
 *
 * @param object $account
 *   (optional) The user account whose default shortcut set will be returned.
 *   If not provided, the function will return the currently logged-in user's
 *   default shortcut set.
 *
 * @return \Drupal\shortcut\ShortcutSetInterface|null
 *   An object representing the default shortcut set.
 *
 * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
 *   \Drupal\shortcut\ShortcutSetStorageInterface::getDefaultSet() instead.
 *
 * @see https://www.drupal.org/node/3427050
 */
function shortcut_default_set($account = NULL) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\shortcut\ShortcutSetStorageInterface::getDefaultSet() instead. See https://www.drupal.org/node/3427050', E_USER_DEPRECATED);
  $user = \Drupal::currentUser();
  if (!isset($account)) {
    $account = $user;
  }

  return \Drupal::entityTypeManager()
    ->getStorage('shortcut_set')
    ->getDefaultSet($account);
}

/**
 * Returns an array of shortcut links, suitable for rendering.
 *
+3 −11
Original line number Diff line number Diff line
@@ -25,21 +25,13 @@ class ShortcutLazyBuilders implements TrustedCallbackInterface {
   *
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entityTypeManager
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\Core\Session\AccountInterface|null $currentUser
   * @param \Drupal\Core\Session\AccountInterface $currentUser
   *   The current user.
   */
  public function __construct(RendererInterface $renderer, protected ?EntityTypeManagerInterface $entityTypeManager, protected ?AccountInterface $currentUser) {
  public function __construct(RendererInterface $renderer, protected EntityTypeManagerInterface $entityTypeManager, protected AccountInterface $currentUser) {
    $this->renderer = $renderer;
    if (!isset($this->entityTypeManager)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $entityTypeManager argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3427050', E_USER_DEPRECATED);
      $this->entityTypeManager = \Drupal::entityTypeManager();
    }
    if (!isset($this->currentUser)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $currentUser argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3427050', E_USER_DEPRECATED);
      $this->currentUser = \Drupal::currentUser();
    }
  }

  /**