Skip to content

Commit

Permalink
Fix missing Url/Translation support for the widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Jan 18, 2024
1 parent 97b5bb4 commit 99985fa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
17 changes: 9 additions & 8 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/Dto/Shortcut.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 11 additions & 12 deletions src/Dto/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand All @@ -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;

Expand All @@ -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);
}
}
10 changes: 10 additions & 0 deletions tests/Controller/DummyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
}
4 changes: 2 additions & 2 deletions tests/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
[
Expand Down

0 comments on commit 99985fa

Please sign in to comment.