fix: 🐛 required validation on wysiwyg + ✨ adapt the hero to the new config
This commit is contained in:
parent
6b2e473ba5
commit
ac121e343d
5 changed files with 234 additions and 64 deletions
128
database/seeders/AddHeroConfigSeeder.php
Normal file
128
database/seeders/AddHeroConfigSeeder.php
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\PageConfig;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AddHeroConfigSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
|
||||
|
||||
// php artisan db:seed --class=AddHeroConfigSeeder
|
||||
$ids = ['39'];
|
||||
$configs = PageConfig::whereIn('id', $ids)->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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +104,7 @@ export default function DynamicInputs({
|
|||
<SimpleWysiwyg
|
||||
name={fieldName}
|
||||
model="DynamicPage"
|
||||
required={extractRequiredValidation(field.validation)}
|
||||
label={getTrans(field.label)}
|
||||
value={String(fieldValue)}
|
||||
setData={setData}
|
||||
|
|
|
|||
|
|
@ -118,9 +118,16 @@ export default function SimpleWysiwyg({
|
|||
const [content, setContent] = useState(value);
|
||||
const [version, setVersion] = useState(1);
|
||||
|
||||
function stripHtmlTags(html: string) {
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = html;
|
||||
const text = temp.textContent || temp.innerText || '';
|
||||
return text.trim() === '' ? null : text;
|
||||
}
|
||||
const onChangeContent = (changedValue: string) => {
|
||||
setContent(changedValue);
|
||||
setData(name, changedValue);
|
||||
const value = stripHtmlTags(changedValue) ? changedValue : '';
|
||||
setContent(value);
|
||||
setData(name, value);
|
||||
};
|
||||
|
||||
const customOptions: UseEditorOptions = {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
<div class="hero fw">
|
||||
<div class="hero__container">
|
||||
@if (!empty($hero) and is_array($hero))
|
||||
<div class="hero fw">
|
||||
<div class="hero__container">
|
||||
|
||||
<div class="swiper-container">
|
||||
<div class="swiper-wrapper">
|
||||
@php
|
||||
<div class="swiper-container">
|
||||
<div class="swiper-wrapper">
|
||||
@php
|
||||
$hero_i = 0;
|
||||
@endphp
|
||||
@foreach($hero as $h)
|
||||
<div class="swiper-slide">
|
||||
<div class="hero__block hero-block image-border-wrap" @if(empty($h['video_file'])) style="background-image: url({{ $h['image'] }});" @endif >
|
||||
@if(!empty($h['video_file']))
|
||||
<div class="hero__video">
|
||||
<video autoplay muted loop playsinline>
|
||||
<source src="{{ $h['video_file'] }}">
|
||||
</video>
|
||||
</div>
|
||||
@endif
|
||||
<div class="hero-block__wrapper wrapper">
|
||||
@if(!empty($h['title']) || !empty($h['subtitle']) || !empty($h['text']))
|
||||
<div class="hero__block-info">
|
||||
@foreach ($hero as $h)
|
||||
<div class="swiper-slide">
|
||||
<div class="hero__block hero-block image-border-wrap"
|
||||
@if (empty($h['video_file'])) style="background-image: url({{ $h['image'] }});" @endif>
|
||||
@if (!empty($h['video_file']))
|
||||
<div class="hero__video">
|
||||
<video autoplay muted loop playsinline>
|
||||
<source src="{{ $h['video_file'] }}">
|
||||
</video>
|
||||
</div>
|
||||
@endif
|
||||
<div class="hero-block__wrapper wrapper">
|
||||
@if (!empty($h['title']) || !empty($h['subtitle']) || !empty($h['text']))
|
||||
<div class="hero__block-info">
|
||||
@if (!empty($h['title']))
|
||||
@if ($hero_i == 0)
|
||||
<h1 class="hero__block-title">{!! $h['title'] !!}</h1>
|
||||
@else
|
||||
<h2 class="hero__block-title">{!! $h['title'] !!}</h2>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@if(!empty($h['title']))
|
||||
@if($hero_i == 0)
|
||||
<h1 class="hero__block-title">{!! $h['title'] !!}</h1>
|
||||
@else
|
||||
<h2 class="hero__block-title">{!! $h['title'] !!}</h2>
|
||||
@endif
|
||||
@endif
|
||||
@if (!empty($h['subtitle']))
|
||||
<div class="hero__block-subtitle">{{ $h['subtitle'] }}</div>
|
||||
@endif
|
||||
|
||||
@if(!empty($h['subtitle']))
|
||||
<div class="hero__block-subtitle">{{ $h['subtitle'] }}</div>
|
||||
@endif
|
||||
|
||||
@if(!empty($h['text']))
|
||||
<div class="hero__block-text description">{!! $h['text'] !!}</div>
|
||||
@endif
|
||||
@if(!empty($h['button']))
|
||||
<a class="btn" href="{{ $h['button']['url'] }}" title="{{ $h['button']['title'] }}">{{ $h["button"]["title"] }} <i class="btn__icon btn__icon_arrow-right"></i></a>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
@endif
|
||||
<div class="hero__nav hero-nav hero-nav_{{ count($hero) }}">
|
||||
<div class="hero-nav__arrow hero-nav__arrow_prev"></div>
|
||||
<div class="hero-nav__arrow hero-nav__arrow_next"></div>
|
||||
</div>
|
||||
</div>
|
||||
@if (!empty($h['text']))
|
||||
<div class="hero__block-text description">{!! $h['text'] !!}</div>
|
||||
@endif
|
||||
@if (!empty($h['button']) && isset($h['button']['url']) && isset($h['button']['title']))
|
||||
<a class="btn" href="{{ $h['button']['url'] }}"
|
||||
title="{{ $h['button']['title'] }}">{{ $h['button']['title'] }} <i
|
||||
class="btn__icon btn__icon_arrow-right"></i></a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
<div class="hero__nav hero-nav hero-nav_{{ count($hero) }}">
|
||||
<div class="hero-nav__arrow hero-nav__arrow_prev"></div>
|
||||
<div class="hero-nav__arrow hero-nav__arrow_next"></div>
|
||||
</div>
|
||||
</div>
|
||||
<x-front.borders :borders="!empty($h['image_borders']) ? $h['image_borders'] : []" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@php
|
||||
</div>
|
||||
@php
|
||||
$hero_i++;
|
||||
@endphp
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<div class="hero__pagination hero__pagination_{{ count($hero) }} slider-pagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<div class="hero__pagination hero__pagination_{{ count($hero) }} slider-pagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="scroll-down"><a class="scroll-down__btn" title="arrow down"><img src="/assets/img/arrow-down.png" alt="arrow-down" /></a></div>
|
||||
<div class="scroll-down"><a class="scroll-down__btn" title="arrow down"><img src="/assets/img/arrow-down.png"
|
||||
alt="arrow-down" /></a></div>
|
||||
@include('front.breadcrumbs.breadcrumb-body')
|
||||
@endif
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue