feat: explicit icon map for hotel cms-data response
This commit is contained in:
@@ -14,7 +14,7 @@ final readonly class CmsHotelData
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed>|null $images
|
||||
* @param array<string, array{label?: string|null, value?: mixed}>|null $icons
|
||||
* @param list<array{icon: string, label: string|false}>|null $icons
|
||||
*/
|
||||
public function __construct(
|
||||
public ?string $name,
|
||||
|
||||
@@ -64,7 +64,7 @@ class CmsDataProvider
|
||||
* room_types?: string,
|
||||
* additional_information?: string,
|
||||
* images?: array<string, mixed>,
|
||||
* icons?: array<string, bool|string>,
|
||||
* icons?: list<array{icon: string, label: string|false}>,
|
||||
* region?: array{
|
||||
* name: string,
|
||||
* latitude: float,
|
||||
|
||||
@@ -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 %}
|
||||
<ul class="grid grid-cols-2 md:grid-cols-3 gap-2">
|
||||
{% 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 %}
|
||||
<li class="flex items-center gap-2">
|
||||
<div class="border-2 border-gray-900 rounded-full w-16 h-16 shrink-0 flex flex-col items-center justify-center">
|
||||
{% if mapping %}
|
||||
{{ icon(mapping.icon, 'w-8 h-8 shrink-0 text-gray-900') }}
|
||||
{% if item.icon %}
|
||||
{{ icon(item.icon, 'w-8 h-8 shrink-0 text-gray-900') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="text-sm font-bold">
|
||||
{% if isBool %}
|
||||
{{ mapping ? mapping.label : '' }}
|
||||
{% else %}
|
||||
{{ mapping ? mapping.label ~ ': ' ~ value : value }}
|
||||
{% if item.label is not same as(false) %}
|
||||
<div class="text-sm font-bold">{{ item.label }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
@@ -23,7 +23,11 @@ class CmsDataProviderTest extends TestCase
|
||||
'room_types' => '<p>Zimmer</p>',
|
||||
'additional_information' => '<p>Weitere Infos</p>',
|
||||
'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('<p>Zimmer</p>', $data->roomTypes);
|
||||
self::assertSame('<p>Weitere Infos</p>', $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('<p>Skigebiet</p>', $data->region->skiArea);
|
||||
|
||||
Reference in New Issue
Block a user