From d4db0cffc6e822c4be55fc1ee224a7190858f7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 2 Oct 2026 19:52:09 +0200 Subject: [PATCH] fix(slides): allow empty text in slide requests and indicate connected visibility in BO --- .../Requests/Bo/Slides/StoreSlideRequest.php | 8 +++- .../Requests/Bo/Slides/UpdateSlideRequest.php | 14 +++++++ lang/en.json | 4 +- lang/fr.json | 4 +- .../views/bo/slides/index-list.blade.php | 3 ++ .../Bo/Slides/StoreSlideRequestTest.php | 40 +++++++++++++++++++ 6 files changed, 70 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/Bo/Slides/StoreSlideRequest.php b/app/Http/Requests/Bo/Slides/StoreSlideRequest.php index 52866990..77186fb2 100644 --- a/app/Http/Requests/Bo/Slides/StoreSlideRequest.php +++ b/app/Http/Requests/Bo/Slides/StoreSlideRequest.php @@ -65,7 +65,13 @@ class StoreSlideRequest extends FormRequest #[\Override] protected function prepareForValidation(): void { + $text = $this->input('text'); + if (is_string($text) && trim(html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8')) === '') { + $text = null; + } + $this->merge([ + 'text' => $text, 'connected' => $this->boolean('connected'), 'link_new_tab' => $this->boolean('link_new_tab'), ]); @@ -82,7 +88,7 @@ class StoreSlideRequest extends FormRequest 'title' => ['required', 'string', 'min:4', 'max:75'], 'picture_alt' => ['required_with:picture', 'string', 'min:4', 'max:75'], 'picture_title' => ['required_with:picture', 'string', 'min:4', 'max:75'], - 'text' => ['required_without:picture', 'string', 'min:5'], + 'text' => ['nullable', 'required_without:picture', 'string', 'min:4'], 'link' => ['nullable', 'url:https', 'max:255'], 'link_label' => ['nullable', 'string', 'min:5', 'max:255'], 'link_new_tab' => ['present', 'boolean:strict'], diff --git a/app/Http/Requests/Bo/Slides/UpdateSlideRequest.php b/app/Http/Requests/Bo/Slides/UpdateSlideRequest.php index 135239b2..bfd7247e 100644 --- a/app/Http/Requests/Bo/Slides/UpdateSlideRequest.php +++ b/app/Http/Requests/Bo/Slides/UpdateSlideRequest.php @@ -25,4 +25,18 @@ class UpdateSlideRequest extends StoreSlideRequest period: $this->toDatePeriod(), ); } + + #[\Override] + public function rules(): array + { + $rules = parent::rules(); + + /** @var \App\Models\Slide|null $slide */ + $slide = $this->route('slide'); + if ($slide && ! empty($slide->picture)) { + $rules['text'] = ['nullable', 'string', 'min:4']; + } + + return $rules; + } } diff --git a/lang/en.json b/lang/en.json index 8f7fddfc..b92093fb 100644 --- a/lang/en.json +++ b/lang/en.json @@ -827,5 +827,7 @@ "town": "town", "your_message": "your_message", "Visible": "Visible", - "Not visible": "Not visible" + "Not visible": "Not visible", + "Connected": "Connected", + "Connected members only": "Connected members only" } diff --git a/lang/fr.json b/lang/fr.json index cb61988a..598405d5 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -814,5 +814,7 @@ "town": "Ville", "your_message": "Votre message", "Visible": "Visible", - "Not visible": "Non visible" + "Not visible": "Non visible", + "Connected": "Connecté", + "Connected members only": "Membres connectés uniquement" } diff --git a/resources/views/bo/slides/index-list.blade.php b/resources/views/bo/slides/index-list.blade.php index 4fc05594..c8598c05 100644 --- a/resources/views/bo/slides/index-list.blade.php +++ b/resources/views/bo/slides/index-list.blade.php @@ -30,6 +30,9 @@ @if ($slide->isVisible()) + @if ($slide->connected) +
{{ __('Connected') }} + @endif @else @endif diff --git a/tests/Feature/App/Http/Requests/Bo/Slides/StoreSlideRequestTest.php b/tests/Feature/App/Http/Requests/Bo/Slides/StoreSlideRequestTest.php index 0abe1c02..1426013b 100644 --- a/tests/Feature/App/Http/Requests/Bo/Slides/StoreSlideRequestTest.php +++ b/tests/Feature/App/Http/Requests/Bo/Slides/StoreSlideRequestTest.php @@ -74,4 +74,44 @@ describe('StoreSlideRequest', function () { // THEN expect(true)->toBeTrue(); }); + + it('normalizes empty text to null in prepareForValidation', function () { + // GIVEN + $authService = mock(AppAdminAuthService::class); + $request = new StoreSlideRequest($authService); + $request->initialize(request: ['text' => '


']); + $method = new \ReflectionMethod($request, 'prepareForValidation'); + $method->setAccessible(true); + + // WHEN + $method->invoke($request); + + // THEN + expect($request->input('text'))->toBeNull(); + }); + + it('allows empty text when picture is present', function () { + // GIVEN + $authService = mock(AppAdminAuthService::class); + $request = new StoreSlideRequest($authService); + $rules = $request->rules(); + + // WHEN + $validator = validator( + [ + 'title' => 'Slide Title', + 'picture' => 'some/picture.jpg', + 'picture_alt' => 'Alt text', + 'picture_title' => 'Title text', + 'text' => null, + 'link_new_tab' => false, + 'connected' => false, + 'client_timezone' => 'Europe/Paris', + ], + $rules + ); + + // THEN + expect($validator->errors()->has('text'))->toBeFalse(); + }); });