diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-28 13:15:56 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-09-03 16:07:49 +0200 |
commit | 4d2556d4cf014edfc5c609dfff5c52e963979b93 (patch) | |
tree | 7a4f3e16a6bacdd863ba40f76a8884206064a0e9 /lib/public/AppFramework/Http/Template/PublicTemplateResponse.php | |
parent | 7b6c78c81d4bd5e280f370b95ca2746cd8693882 (diff) | |
download | nextcloud-server-4d2556d4cf014edfc5c609dfff5c52e963979b93.tar.gz nextcloud-server-4d2556d4cf014edfc5c609dfff5c52e963979b93.zip |
refactor(IMenuAction): Make public menu actions use the new Vue UI
This removes custom rendering code an replaces it with the declarative menu actions.
Also adjust the template to allow the Vue UI to mount.
Custom entries still are possible.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib/public/AppFramework/Http/Template/PublicTemplateResponse.php')
-rw-r--r-- | lib/public/AppFramework/Http/Template/PublicTemplateResponse.php | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php index c12cf087755..b89c84f297f 100644 --- a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php +++ b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php @@ -8,6 +8,7 @@ namespace OCP\AppFramework\Http\Template; use InvalidArgumentException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IInitialStateService; /** * Class PublicTemplateResponse @@ -20,6 +21,7 @@ use OCP\AppFramework\Http\TemplateResponse; class PublicTemplateResponse extends TemplateResponse { private $headerTitle = ''; private $headerDetails = ''; + /** @var IMenuAction[] */ private $headerActions = []; private $footerVisible = true; @@ -33,9 +35,38 @@ class PublicTemplateResponse extends TemplateResponse { * @param H $headers * @since 14.0.0 */ - public function __construct(string $appName, string $templateName, array $params = [], $status = Http::STATUS_OK, array $headers = []) { + public function __construct( + string $appName, + string $templateName, + array $params = [], + $status = Http::STATUS_OK, + array $headers = [], + ) { parent::__construct($appName, $templateName, $params, 'public', $status, $headers); - \OC_Util::addScript('core', 'public/publicpage'); + \OCP\Util::addScript('core', 'public-page-menu'); + + $state = \OCP\Server::get(IInitialStateService::class); + $state->provideLazyInitialState('core', 'public-page-menu', function () { + $response = []; + foreach ($this->headerActions as $action) { + // First try in it is a custom action that provides rendered HTML + $rendered = $action->render(); + if ($rendered === '') { + // If simple action, add the response data + if ($action instanceof SimpleMenuAction) { + $response[] = $action->getData(); + } + } else { + // custom action so add the rendered output + $response[] = [ + 'id' => $action->getId(), + 'label' => $action->getLabel(), + 'html' => $rendered, + ]; + } + } + return $response; + }); } /** @@ -128,16 +159,4 @@ class PublicTemplateResponse extends TemplateResponse { public function getFooterVisible(): bool { return $this->footerVisible; } - - /** - * @return string - * @since 14.0.0 - */ - public function render(): string { - $params = array_merge($this->getParams(), [ - 'template' => $this, - ]); - $this->setParams($params); - return parent::render(); - } } |