SimpleMenuAction.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\AppFramework\Http\Template;
  7. /**
  8. * Class SimpleMenuAction
  9. *
  10. * @since 14.0.0
  11. */
  12. class SimpleMenuAction implements IMenuAction {
  13. /** @var string */
  14. private $id;
  15. /** @var string */
  16. private $label;
  17. /** @var string */
  18. private $icon;
  19. /** @var string */
  20. private $link;
  21. /** @var int */
  22. private $priority;
  23. /** @var string */
  24. private $detail;
  25. /**
  26. * SimpleMenuAction constructor.
  27. *
  28. * @param string $id
  29. * @param string $label
  30. * @param string $icon
  31. * @param string $link
  32. * @param int $priority
  33. * @param string $detail
  34. * @since 14.0.0
  35. */
  36. public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
  37. $this->id = $id;
  38. $this->label = $label;
  39. $this->icon = $icon;
  40. $this->link = $link;
  41. $this->priority = $priority;
  42. $this->detail = $detail;
  43. }
  44. /**
  45. * @return string
  46. * @since 14.0.0
  47. */
  48. public function getId(): string {
  49. return $this->id;
  50. }
  51. /**
  52. * @return string
  53. * @since 14.0.0
  54. */
  55. public function getLabel(): string {
  56. return $this->label;
  57. }
  58. /**
  59. * The icon CSS class to use.
  60. *
  61. * @return string
  62. * @since 14.0.0
  63. */
  64. public function getIcon(): string {
  65. return $this->icon;
  66. }
  67. /**
  68. * @return string
  69. * @since 14.0.0
  70. */
  71. public function getLink(): string {
  72. return $this->link;
  73. }
  74. /**
  75. * @return int
  76. * @since 14.0.0
  77. */
  78. public function getPriority(): int {
  79. return $this->priority;
  80. }
  81. /**
  82. * Custom render function.
  83. * The returned HTML must be wrapped within a listitem (`<li>...</li>`).
  84. * * If an empty string is returned, the default design is used (based on the label and link specified).
  85. * @return string
  86. * @since 14.0.0
  87. */
  88. public function render(): string {
  89. return '';
  90. }
  91. /**
  92. * Return JSON data to let the frontend render the menu entry.
  93. * @return array{id: string, label: string, href: string, icon: string, details: string|null}
  94. * @since 31.0.0
  95. */
  96. public function getData(): array {
  97. return [
  98. 'id' => $this->id,
  99. 'label' => $this->label,
  100. 'href' => $this->link,
  101. 'icon' => $this->icon,
  102. 'details' => $this->detail,
  103. ];
  104. }
  105. }