From ac121e343dcd9944964554a36adf37ea8ee4aee5 Mon Sep 17 00:00:00 2001 From: K Muller Date: Fri, 21 Nov 2025 16:17:23 +0100 Subject: [PATCH] fix: :bug: required validation on wysiwyg + :sparkles: adapt the hero to the new config --- database/seeders/AddHeroConfigSeeder.php | 128 +++++++++++++++++ .../Components/DynamicPages/DynamicInputs.tsx | 1 + .../back/Components/Inputs/SimpleWysiwyg.tsx | 11 +- .../views/components/front/hero.blade.php | 135 +++++++++++------- .../views/front/layouts/layout.blade.php | 23 +-- 5 files changed, 234 insertions(+), 64 deletions(-) create mode 100644 database/seeders/AddHeroConfigSeeder.php diff --git a/database/seeders/AddHeroConfigSeeder.php b/database/seeders/AddHeroConfigSeeder.php new file mode 100644 index 00000000..b4474259 --- /dev/null +++ b/database/seeders/AddHeroConfigSeeder.php @@ -0,0 +1,128 @@ +get(); + + $localesToPopulate = ['fr', "en"]; + + foreach($localesToPopulate as $locale) { + app()->setLocale($locale); + + $newObject = [ + "key" => "list_hero", + "order" => 100, + "type" => 9, + "label" => "Hero Section", + "validation" => "required|array|min:1|max:1", + "children" => [ + [ + "key" => "string_hero_title", + "order" => 1, + "type" => 1, + "label" => $locale === "fr" ? "Titre": "Title", + "validation" => "nullable|string|max:255", + "children" => [] + ], + [ + "key" => "string_hero_subtitle", + "order" => 2, + "type" => 1, + "label" => $locale === "fr" ? "Sous-titre" : "Subtitle", + "validation" => "nullable|string|max:255" + ], + [ + "key" => "wysiwyg_hero_description", + "order" => 3, + "type" => 3, + "label" => "Description", + "validation" => "nullable|string|min:15|max:400" + ], + [ + "key" => "list_hero_cta", + "order" => 4, + "type" => 9, + "label" => "CTA", + "validation" => "nullable|array|min:0|max:1", + "children" => [ + [ + "key" => "string_hero_cta_label", + "order" => 1, + "type" => 1, + "label" => "Label", + "validation" => "required|string|min:1|max:60", + "children" => [] + ], + [ + "key" => "string_hero_cta_url", + "order" => 2, + "type" => 1, + "label" => "URL", + "validation" => "required|string|min:1|max:255", + "children" => [] + ] + ] + ], + [ + "key" => "list_media_list", + "order" => 5, + "type" => 9, + "label" => $locale === "fr" ? "Médias" : "Medias", + "validation" => "required|array|min:1|max:5", + "children" => [ + [ + "key" => "string_local_video", + "order" => 1, + "type" => 1, + "label" => $locale === "fr" ? "Vidéo Locale" : "Local Video", + "validation" => "nullable|string|max:255" + ], + [ + "key" => "image_picture", + "order" => 2, + "type" => 8, + "label" => "Image", + "validation" => "nullable|file|mimes:jpg,jpeg,png,webp|max:5120|dimensions:width=1600,height=768" + ], + [ + "key" => "string_media_alt", + "order" => 3, + "type" => 1, + "label" => $locale === "fr" ? "Champ Alternatif" : "Text Alt", + "validation" => "required|string|between:3,255", + "children" => [] + ] + ] + ] + ] + ]; + + + + + foreach ($configs as $config) { + $configTranslations = $config->getTranslations('config'); + $configData = $configTranslations[$locale] ?? []; + $configData[] = $newObject; + $configTranslations[$locale] = $configData; + $config->setTranslations('config', $configTranslations); + $config->save(); + } + } + } +} diff --git a/resources/ts/back/Components/DynamicPages/DynamicInputs.tsx b/resources/ts/back/Components/DynamicPages/DynamicInputs.tsx index 455d7735..9ad76d82 100644 --- a/resources/ts/back/Components/DynamicPages/DynamicInputs.tsx +++ b/resources/ts/back/Components/DynamicPages/DynamicInputs.tsx @@ -104,6 +104,7 @@ export default function DynamicInputs({ { - setContent(changedValue); - setData(name, changedValue); + const value = stripHtmlTags(changedValue) ? changedValue : ''; + setContent(value); + setData(name, value); }; const customOptions: UseEditorOptions = { diff --git a/resources/views/components/front/hero.blade.php b/resources/views/components/front/hero.blade.php index 5aa2dfe9..45970f64 100644 --- a/resources/views/components/front/hero.blade.php +++ b/resources/views/components/front/hero.blade.php @@ -2,71 +2,98 @@ global $chirkashi; @endphp +@php + $firstHero = isset($dynamicPageModel) ? data_get($dynamicPageModel, 'content.list_hero.0', []) : []; + $mediaList = data_get($firstHero, 'list_media_list', []); + $hero = collect($mediaList) + ->map(function ($media, $index) use ($firstHero) { + return [ + 'title' => isset($firstHero['string_hero_title']) ? clean($firstHero['string_hero_title']) : null, + 'subtitle' => $firstHero['string_hero_subtitle'] ?? null, + 'text' => isset($firstHero['wysiwyg_hero_description']) + ? clean($firstHero['wysiwyg_hero_description']) + : null, + 'button' => [ + 'url' => data_get($firstHero, 'list_hero_cta.0.string_hero_cta_url'), + 'title' => data_get($firstHero, 'list_hero_cta.0.string_hero_cta_label'), + ], + 'video_file' => !empty($media['string_local_video']) ? asset($media['string_local_video']) : null, + 'image' => !empty($media['image_picture']) ? asset($media['image_picture']) : null, + 'image_borders' => [ + 'desktop' => ['left' => true, 'right' => true, 'top' => true, 'bottom' => true], + 'mobile' => ['left' => false, 'right' => false, 'top' => false, 'bottom' => true], + ], + ]; + }) + ->all(); +@endphp -@if(!empty($hero) and is_array($hero)) -
-
+@if (!empty($hero) and is_array($hero)) +
+
-
-
- @php +
+
+ @php $hero_i = 0; @endphp - @foreach($hero as $h) -
-
- @if(!empty($h['video_file'])) -
- -
- @endif -
- @if(!empty($h['title']) || !empty($h['subtitle']) || !empty($h['text'])) -
+ @foreach ($hero as $h) +
+
+ @if (!empty($h['video_file'])) +
+ +
+ @endif +
+ @if (!empty($h['title']) || !empty($h['subtitle']) || !empty($h['text'])) +
+ @if (!empty($h['title'])) + @if ($hero_i == 0) +

{!! $h['title'] !!}

+ @else +

{!! $h['title'] !!}

+ @endif + @endif - @if(!empty($h['title'])) - @if($hero_i == 0) -

{!! $h['title'] !!}

- @else -

{!! $h['title'] !!}

- @endif - @endif + @if (!empty($h['subtitle'])) +
{{ $h['subtitle'] }}
+ @endif - @if(!empty($h['subtitle'])) -
{{ $h['subtitle'] }}
- @endif - - @if(!empty($h['text'])) -
{!! $h['text'] !!}
- @endif - @if(!empty($h['button'])) - {{ $h["button"]["title"] }} - @endif - -
- @endif -
-
-
-
-
+ @if (!empty($h['text'])) +
{!! $h['text'] !!}
+ @endif + @if (!empty($h['button']) && isset($h['button']['url']) && isset($h['button']['title'])) + {{ $h['button']['title'] }} + @endif +
+ @endif +
+
+
+
+
-
+
-
- @php +
+ @php $hero_i++; @endphp - @endforeach -
-
-
-
-
+ @endforeach +
+
+
+
+
- + @include('front.breadcrumbs.breadcrumb-body') @endif diff --git a/resources/views/front/layouts/layout.blade.php b/resources/views/front/layouts/layout.blade.php index e285c0f9..c7cf8728 100644 --- a/resources/views/front/layouts/layout.blade.php +++ b/resources/views/front/layouts/layout.blade.php @@ -1,15 +1,19 @@ @php /** FIXME: Dans le wp, la méthode wp_is_mobile() est utilisée. - * Il faudra dapater les templates utilisant cette variable pour gérer le cas dans le style plutôt qu'en php j'imagine. - * $mob = wp_is_mobile() - */ + * Il faudra dapater les templates utilisant cette variable pour gérer le cas dans le style plutôt qu'en php j'imagine. + * $mob = wp_is_mobile() + */ $mob = true; global $chirkashi; - $chirkashi['top'] = 'chirk_top'; - $chirkashi['bottom'] = 'chirkashi_bottom'; - $chirkashi['left'] = ''; - $chirkashi['right'] = 'chirkashi_right'; + $chirkashi['top'] = + 'chirk_top'; + $chirkashi['bottom'] = + 'chirkashi_bottom'; + $chirkashi['left'] = + ''; + $chirkashi['right'] = + 'chirkashi_right'; @endphp @@ -20,7 +24,9 @@ @include('front.layouts.head') - + @include('front.layouts.top-nav-menu')
@include('front.layouts.header') @@ -29,6 +35,7 @@
+ @yield('content')