INavigationManager.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP;
  10. /**
  11. * Manages the ownCloud navigation
  12. * @since 6.0.0
  13. *
  14. * @psalm-type NavigationEntry = array{id: string, order: int, href: string, name: string, app?: string, icon?: string, classes?: string, type?: string}
  15. */
  16. interface INavigationManager {
  17. /**
  18. * Navigation entries of the app navigation
  19. * @since 16.0.0
  20. */
  21. public const TYPE_APPS = 'link';
  22. /**
  23. * Navigation entries of the settings navigation
  24. * @since 16.0.0
  25. */
  26. public const TYPE_SETTINGS = 'settings';
  27. /**
  28. * Navigation entries for public page footer navigation
  29. * @since 16.0.0
  30. */
  31. public const TYPE_GUEST = 'guest';
  32. /**
  33. * Creates a new navigation entry
  34. *
  35. * @param array array|\Closure $entry Array containing: id, name, order, icon and href key
  36. * If a menu entry (type = 'link') is added, you shall also set app to the app that added the entry.
  37. * The use of a closure is preferred, because it will avoid
  38. * loading the routing of your app, unless required.
  39. * @psalm-param NavigationEntry|callable():NavigationEntry $entry
  40. * @return void
  41. * @since 6.0.0
  42. */
  43. public function add($entry);
  44. /**
  45. * Sets the current navigation entry of the currently running app
  46. * @param string $appId id of the app entry to activate (from added $entry)
  47. * @return void
  48. * @since 6.0.0
  49. */
  50. public function setActiveEntry($appId);
  51. /**
  52. * Get the current navigation entry of the currently running app
  53. * @return string
  54. * @since 20.0.0
  55. */
  56. public function getActiveEntry();
  57. /**
  58. * Get a list of navigation entries
  59. *
  60. * @param string $type type of the navigation entries
  61. * @return array
  62. * @since 14.0.0
  63. */
  64. public function getAll(string $type = self::TYPE_APPS): array;
  65. /**
  66. * Set an unread counter for navigation entries
  67. *
  68. * @param string $id id of the navigation entry
  69. * @param int $unreadCounter Number of unread entries (0 to hide the counter which is the default)
  70. * @since 22.0.0
  71. */
  72. public function setUnreadCounter(string $id, int $unreadCounter): void;
  73. /**
  74. * Get a navigation entry by id.
  75. *
  76. * @param string $id ID of the navigation entry
  77. * @since 31.0.0
  78. */
  79. public function get(string $id): array|null;
  80. /**
  81. * Returns the id of the user's default entry
  82. *
  83. * If `user` is not passed, the currently logged in user will be used
  84. *
  85. * @param ?IUser $user User to query default entry for
  86. * @param bool $withFallbacks Include fallback values if no default entry was configured manually
  87. * Before falling back to predefined default entries,
  88. * the user defined entry order is considered and the first entry would be used as the fallback.
  89. * @since 31.0.0
  90. */
  91. public function getDefaultEntryIdForUser(?IUser $user = null, bool $withFallbacks = true): string;
  92. /**
  93. * Get the global default entries with fallbacks
  94. *
  95. * @return string[] The default entries
  96. * @since 31.0.0
  97. */
  98. public function getDefaultEntryIds(): array;
  99. /**
  100. * Set the global default entries with fallbacks
  101. *
  102. * @param string[] $ids
  103. * @throws \InvalidArgumentException If any of the entries is not available
  104. * @since 31.0.0
  105. */
  106. public function setDefaultEntryIds(array $ids): void;
  107. }