From 99985faca48510a1a7e604963fcfd39cf07d1bab Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 18 Jan 2024 21:55:50 +0100 Subject: [PATCH] Fix missing Url/Translation support for the widget --- src/DependencyInjection/Configuration.php | 17 +++++++++-------- src/Dto/Shortcut.php | 6 ++++++ src/Dto/Widget.php | 23 +++++++++++------------ tests/Controller/DummyController.php | 10 ++++++++++ tests/config.php | 4 ++-- 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 0290fa5..3ddb1d4 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -564,17 +564,18 @@ private function setupWidgets(ArrayNodeDefinition $node): void 'The template to use to display the widget in the operating system widgets dashboard. Note: this property is currently only informational and not used. See ms_ac_template below.' ) ->end() - ->scalarNode('ms_ac_template') - ->isRequired() - ->info( - 'The URL of the custom Adaptive Cards template to use to display the widget in the operating system widgets dashboard. See Define a widget template below.' + ->append( + $this->getUrlNode( + 'ms_ac_template', + 'The URL of the custom Adaptive Cards template to use to display the widget in the operating system widgets dashboard.' ) - ->end() - ->scalarNode('data') - ->info( + ) + ->append( + $this->getUrlNode( + 'data', 'The URL where the data to fill the template with can be found. If present, this URL is required to return valid JSON.' ) - ->end() + ) ->scalarNode('type') ->info('The MIME type for the widget data.') ->end() diff --git a/src/Dto/Shortcut.php b/src/Dto/Shortcut.php index 553c9ed..985906a 100644 --- a/src/Dto/Shortcut.php +++ b/src/Dto/Shortcut.php @@ -30,6 +30,12 @@ public function getName(): string|TranslatableInterface $this->provideTranslation($this->name); } + #[SerializedName('short_name')] + public function getShortName(): string|TranslatableInterface + { + $this->provideTranslation($this->shortName); + } + public function getDescription(): string|TranslatableInterface { return $this->provideTranslation($this->description); diff --git a/src/Dto/Widget.php b/src/Dto/Widget.php index 84c1b82..acc5074 100644 --- a/src/Dto/Widget.php +++ b/src/Dto/Widget.php @@ -5,11 +5,12 @@ namespace SpomkyLabs\PwaBundle\Dto; use Symfony\Component\Serializer\Attribute\SerializedName; -use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatableInterface; final class Widget { + use TranslatableTrait; + public string $name; #[SerializedName('short_name')] @@ -32,9 +33,9 @@ final class Widget public null|string $template = null; #[SerializedName('ms_ac_template')] - public string $adaptativeCardTemplate; + public Url $adaptativeCardTemplate; - public null|string $data = null; + public null|Url $data = null; public null|string $type = null; @@ -46,19 +47,17 @@ final class Widget public function getName(): string|TranslatableInterface { - if (! interface_exists(TranslatableInterface::class)) { - return $this->name; - } + return $this->provideTranslation($this->name); + } - return new TranslatableMessage($this->name); + #[SerializedName('short_name')] + public function getShortName(): string|TranslatableInterface + { + return $this->provideTranslation($this->shortName); } public function getDescription(): string|TranslatableInterface { - if (! interface_exists(TranslatableInterface::class) || $this->description === null) { - return $this->description; - } - - return new TranslatableMessage($this->description); + return $this->provideTranslation($this->description); } } diff --git a/tests/Controller/DummyController.php b/tests/Controller/DummyController.php index f5df3ad..d79b081 100644 --- a/tests/Controller/DummyController.php +++ b/tests/Controller/DummyController.php @@ -26,4 +26,14 @@ public function dummy2(string $param1, string $param2): void public function agenda(string $date): void { } + + #[Route('/widget/template', name: 'app_widget_template')] + public function widgetTemplate(): void + { + } + + #[Route('/widget/data', name: 'app_widget_data')] + public function widgetData(): void + { + } } diff --git a/tests/config.php b/tests/config.php index 3bd2f61..cc969ee 100644 --- a/tests/config.php +++ b/tests/config.php @@ -191,8 +191,8 @@ 'description' => 'widget to control the PWAmp music player', 'tag' => 'pwamp', 'template' => 'pwamp-template', - 'ms_ac_template' => '/widgets/mini-player-template.json', - 'data' => 'widgets/mini-player-data.json', + 'ms_ac_template' => 'app_widget_template', + 'data' => 'app_widget_data', 'type' => 'application/json', 'screenshots' => [ [