From 0a1683667f63dabdac5ab51409ba7e0d6554c272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 20 Aug 2026 14:45:05 +0200 Subject: [PATCH] feat: explicit icon map for hotel cms-data response --- src/Model/CmsHotelData.php | 4 ++-- src/Service/CmsDataProvider.php | 2 +- templates/groups/offer/view.html.twig | 30 ++++++--------------------- tests/Service/CmsDataProviderTest.php | 12 +++++++++-- 4 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/Model/CmsHotelData.php b/src/Model/CmsHotelData.php index 745c1ce..d459e98 100644 --- a/src/Model/CmsHotelData.php +++ b/src/Model/CmsHotelData.php @@ -13,8 +13,8 @@ namespace App\Model; final readonly class CmsHotelData { /** - * @param array|null $images - * @param array|null $icons + * @param array|null $images + * @param list|null $icons */ public function __construct( public ?string $name, diff --git a/src/Service/CmsDataProvider.php b/src/Service/CmsDataProvider.php index ab0342d..ea322c1 100644 --- a/src/Service/CmsDataProvider.php +++ b/src/Service/CmsDataProvider.php @@ -64,7 +64,7 @@ class CmsDataProvider * room_types?: string, * additional_information?: string, * images?: array, - * icons?: array, + * icons?: list, * region?: array{ * name: string, * latitude: float, diff --git a/templates/groups/offer/view.html.twig b/templates/groups/offer/view.html.twig index f8a8001..b194dfd 100644 --- a/templates/groups/offer/view.html.twig +++ b/templates/groups/offer/view.html.twig @@ -109,36 +109,18 @@ } %} {% block body %} {% set icons = ctx.hotelCmsData.icons %} - {% set iconMap = { - bedsCount: { icon: 'bed', label: 'Anzahl Betten' }, - parkingCount: { icon: 'parking', label: 'Anzahl Parkplätze' }, - altitude: { icon: 'mountain', label: 'Höhe' }, - partyroom: { icon: 'party', label: 'Partyraum' }, - gamesroom: { icon: 'dice', label: 'Spieleraum' }, - distanceBus: { icon: 'bus', label: 'Entfernung Bus' }, - distanceLift: { icon: 'lift', label: 'Entfernung Lifte' }, - sauna: { icon: 'sauna', label: 'Sauna' }, - shower: { icon: 'shower', label: 'Dusche' }, - wifi: { icon: 'wifi', label: 'WiFi' }, - } %} {% if icons is not empty %}
    - {% for key, value in icons %} - {% set mapping = iconMap[key] ?? null %} - {% set isBool = value is same as(true) or value is same as(false) %} + {% for item in icons %}
  • - {% if mapping %} - {{ icon(mapping.icon, 'w-8 h-8 shrink-0 text-gray-900') }} - {% endif %} -
    -
    - {% if isBool %} - {{ mapping ? mapping.label : '' }} - {% else %} - {{ mapping ? mapping.label ~ ': ' ~ value : value }} + {% if item.icon %} + {{ icon(item.icon, 'w-8 h-8 shrink-0 text-gray-900') }} {% endif %}
    + {% if item.label is not same as(false) %} +
    {{ item.label }}
    + {% endif %}
  • {% endfor %}
diff --git a/tests/Service/CmsDataProviderTest.php b/tests/Service/CmsDataProviderTest.php index 690cfee..283421b 100644 --- a/tests/Service/CmsDataProviderTest.php +++ b/tests/Service/CmsDataProviderTest.php @@ -23,7 +23,11 @@ class CmsDataProviderTest extends TestCase 'room_types' => '

Zimmer

', 'additional_information' => '

Weitere Infos

', 'images' => ['resized' => ['l' => [['url' => 'l.jpg', 'alt' => 'Alt']]]], - 'icons' => ['sauna' => ['label' => 'Sauna', 'value' => true]], + 'icons' => [ + ['icon' => 'bed', 'label' => '69 Betten'], + ['icon' => 'wifi', 'label' => 'WiFi'], + ['icon' => 'sauna', 'label' => false], + ], 'region' => [ 'name' => 'Alpenregion', 'latitude' => 47.1, @@ -50,7 +54,11 @@ class CmsDataProviderTest extends TestCase self::assertSame("Musterstraße 1\n1234 Musterort", $data->address); self::assertSame('

Zimmer

', $data->roomTypes); self::assertSame('

Weitere Infos

', $data->additionalInformation); - self::assertSame(['sauna' => ['label' => 'Sauna', 'value' => true]], $data->icons); + self::assertSame([ + ['icon' => 'bed', 'label' => '69 Betten'], + ['icon' => 'wifi', 'label' => 'WiFi'], + ['icon' => 'sauna', 'label' => false], + ], $data->icons); self::assertNotNull($data->region); self::assertSame('Alpenregion', $data->region->name); self::assertSame('

Skigebiet

', $data->region->skiArea);