From b23dc020f05b1ca9ee565809317fb98f867fb804 Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Wed, 11 Feb 2026 16:56:24 +0000 Subject: [PATCH] Refactor Girls in Digital Week Blade template and Nova resource to streamline dynamic content handling. Remove unused locale field methods and simplify content retrieval logic. Update HTML structure for better styling and responsiveness. --- app/GirlsInDigitalPage.php | 6 +- app/Nova/GirlsInDigitalPage.php | 182 ++++-------------- .../static/girls-in-digital-week.blade.php | 135 +++++-------- 3 files changed, 91 insertions(+), 232 deletions(-) diff --git a/app/GirlsInDigitalPage.php b/app/GirlsInDigitalPage.php index 5dfabff37..b08bbf704 100644 --- a/app/GirlsInDigitalPage.php +++ b/app/GirlsInDigitalPage.php @@ -160,7 +160,8 @@ public static function contentKeyToColumn(string $key): string } /** - * Get content for a key in the current locale: locale override, then main (English) column, then lang file. + * Get content for a key in the current locale: locale override, then main (English) column. + * Returns empty string when blank (no static/lang fallback) so sections can stay empty. */ public function contentForLocale(string $key, ?string $locale = null): string { @@ -176,7 +177,8 @@ public function contentForLocale(string $key, ?string $locale = null): string return (string) $value; } } - return (string) __('girls-in-digital.' . $key); + + return ''; } /** diff --git a/app/Nova/GirlsInDigitalPage.php b/app/Nova/GirlsInDigitalPage.php index 43911469e..a7375528d 100644 --- a/app/Nova/GirlsInDigitalPage.php +++ b/app/Nova/GirlsInDigitalPage.php @@ -9,7 +9,6 @@ use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Text; -use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Fields\Trix; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Panel; @@ -85,59 +84,6 @@ public static function indexQuery(NovaRequest $request, $query) return $query->where('id', 1); } - private static function localesSorted(): array - { - $locales = config('app.locales', ['en']); - if (is_string($locales)) { - $locales = array_map('trim', explode(',', $locales)); - } - $locales = array_values(array_filter($locales)); - if (empty($locales)) { - $locales = ['en']; - } - sort($locales); - return $locales; - } - - /** Build a Text/Textarea/Trix that reads/writes locale_overrides[$locale][$key]. */ - private function localeField(string $label, string $locale, string $key, bool $textarea = false, bool $rich = false): Text|Textarea|Trix - { - $attr = 'locale_' . $locale . '_' . $key; - if ($rich) { - $field = Trix::make($label, $attr)->nullable(); - } else { - $field = $textarea - ? Textarea::make($label, $attr)->nullable() - : Text::make($label, $attr)->nullable(); - } - $field->resolveUsing(function () use ($locale, $key) { - if (! $this->resource) { - return ''; - } - $overrides = $this->resource->locale_overrides ?? []; - return $overrides[$locale][$key] ?? ''; - }); - $field->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) { - try { - $value = $request->get($requestAttribute); - $overrides = $model->locale_overrides ?? []; - if (! isset($overrides[$locale])) { - $overrides[$locale] = []; - } - $overrides[$locale][$key] = $value; - $model->locale_overrides = $overrides; - } catch (\Throwable $e) { - \Illuminate\Support\Facades\Log::error('GirlsInDigital locale field fill failed: ' . $attribute, [ - 'exception' => $e->getMessage(), - 'file' => $e->getFile(), - 'line' => $e->getLine(), - ]); - throw $e; - } - }); - return $field; - } - /** Build the 4 fields for one button (enabled, url, label, open_new_tab). */ private function buttonFields(string $key, string $title): array { @@ -173,130 +119,70 @@ public function fields(Request $request): array } } - /** - * Build locale fields for "Other languages" (non-English). English is always first in each section. - */ - private function otherLocaleFields(array $locales, array $specs): array - { - $fields = []; - foreach ($locales as $locale) { - if ($locale === 'en') { - continue; - } - foreach ($specs as $spec) { - $fields[] = $this->localeField( - $spec['label'] . ' (' . strtoupper($locale) . ')', - $locale, - $spec['key'], - $spec['textarea'] ?? false, - $spec['rich'] ?? false - ); - } - } - return $fields; - } - private function buildFields(Request $request): array { - $locales = self::localesSorted(); - - // — Hero: English first, then other languages, then buttons + // — Hero: English only, then buttons $heroFields = [ Boolean::make('Use dynamic content for this section', 'hero_dynamic') ->help('When on, hero uses the content below.'), - \Laravel\Nova\Fields\Heading::make('English'), - Trix::make('Hero intro (English)', 'hero_intro')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Text::make('Hero video URL (English)', 'hero_video_url')->nullable()->help('YouTube embed URL.'), - Text::make('Hero image (English)', 'hero_image')->nullable(), + Trix::make('Hero intro', 'hero_intro')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Hero video URL', 'hero_video_url')->nullable()->help('YouTube embed URL.'), + Text::make('Hero image', 'hero_image')->nullable(), ]; - $heroFields[] = \Laravel\Nova\Fields\Heading::make('Other languages'); - $heroFields = array_merge($heroFields, $this->otherLocaleFields($locales, [ - ['label' => 'Hero intro', 'key' => 'hero_intro', 'textarea' => true, 'rich' => true], - ['label' => 'Hero video URL', 'key' => 'hero_video_url'], - ])); foreach (self::buttonKeysBySection()['hero'] as $key => $title) { $heroFields = array_merge($heroFields, $this->buttonFields($key, $title)); } - // — About: English first, then other languages, then buttons + // — About: English only, then buttons $aboutFields = [ Boolean::make('Use dynamic content for this section', 'about_dynamic'), - \Laravel\Nova\Fields\Heading::make('English'), - Text::make('About title (English)', 'about_title')->nullable(), - Trix::make('About description 1 (English)', 'about_description_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Trix::make('About description 2 (English)', 'about_description_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Text::make('About image (English)', 'about_image')->nullable(), + Text::make('About title', 'about_title')->nullable(), + Trix::make('About description 1', 'about_description_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Trix::make('About description 2', 'about_description_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('About image', 'about_image')->nullable(), ]; - $aboutFields[] = \Laravel\Nova\Fields\Heading::make('Other languages'); - $aboutFields = array_merge($aboutFields, $this->otherLocaleFields($locales, [ - ['label' => 'About title', 'key' => 'about_title'], - ['label' => 'About description 1', 'key' => 'about_description_1', 'textarea' => true, 'rich' => true], - ['label' => 'About description 2', 'key' => 'about_description_2', 'textarea' => true, 'rich' => true], - ])); foreach (self::buttonKeysBySection()['about'] as $key => $title) { $aboutFields = array_merge($aboutFields, $this->buttonFields($key, $title)); } - // — Resources: English first, then other languages, then buttons + // — Resources: English only, then buttons $resourcesFields = [ Boolean::make('Use dynamic content for this section', 'resources_dynamic'), - \Laravel\Nova\Fields\Heading::make('English'), - Text::make('Resources title (English)', 'resource_title')->nullable(), - Text::make('Young person / parent title (English)', 'resource_person_title')->nullable(), - Trix::make('Young person / parent description 1 (English)', 'resource_person_description_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Trix::make('Young person / parent description 2 (English)', 'resource_person_description_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Text::make('Young person / parent image (English)', 'resource_young_image')->nullable(), - Text::make('Educator title (English)', 'resource_educator_title')->nullable(), - Trix::make('Educator description (English)', 'resource_educator_description')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Text::make('Educator image (English)', 'resource_educator_image')->nullable(), + Text::make('Resources title', 'resource_title')->nullable(), + Text::make('Young person / parent title', 'resource_person_title')->nullable(), + Trix::make('Young person / parent description 1', 'resource_person_description_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Trix::make('Young person / parent description 2', 'resource_person_description_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Young person / parent image', 'resource_young_image')->nullable(), + Text::make('Educator title', 'resource_educator_title')->nullable(), + Trix::make('Educator description', 'resource_educator_description')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Educator image', 'resource_educator_image')->nullable(), ]; - $resourcesFields[] = \Laravel\Nova\Fields\Heading::make('Other languages'); - $resourcesFields = array_merge($resourcesFields, $this->otherLocaleFields($locales, [ - ['label' => 'Resource title', 'key' => 'resource_title'], - ['label' => 'Young person title', 'key' => 'resource_person_title'], - ['label' => 'Young person description 1', 'key' => 'resource_person_description_1', 'textarea' => true, 'rich' => true], - ['label' => 'Young person description 2', 'key' => 'resource_person_description_2', 'textarea' => true, 'rich' => true], - ['label' => 'Educator title', 'key' => 'resource_educator_title'], - ['label' => 'Educator description', 'key' => 'resource_educator_description', 'textarea' => true, 'rich' => true], - ])); foreach (self::buttonKeysBySection()['resources'] as $key => $title) { $resourcesFields = array_merge($resourcesFields, $this->buttonFields($key, $title)); } - // — Why Matters: English first, then other languages + // — Why Matters: English only $mattersFields = [ Boolean::make('Use dynamic content for this section', 'matters_dynamic'), - \Laravel\Nova\Fields\Heading::make('English'), - Text::make('Section title (English)', 'matters_title')->nullable(), - Text::make('Graph 1 image (English)', 'matters_graph1_image')->nullable(), - Text::make('Graph 1 link (English)', 'matters_graph1_link')->nullable(), - Trix::make('Graph 1 caption (English)', 'matters_graph1_caption')->nullable(), - Text::make('Graph 2 image (English)', 'matters_graph2_image')->nullable(), - Text::make('Graph 2 link (English)', 'matters_graph2_link')->nullable(), - Trix::make('Graph 2 caption (English)', 'matters_graph2_caption')->nullable(), - Text::make('Graph 3 image (English)', 'matters_graph3_image')->nullable(), - Text::make('Graph 3 link (English)', 'matters_graph3_link')->nullable(), - Trix::make('Graph 3 caption (English)', 'matters_graph3_caption')->nullable(), - Trix::make('Paragraph 1 (English)', 'matters_paragraph_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), - Trix::make('Paragraph 2 (English)', 'matters_paragraph_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Section title', 'matters_title')->nullable(), + Text::make('Graph 1 image', 'matters_graph1_image')->nullable(), + Text::make('Graph 1 link', 'matters_graph1_link')->nullable(), + Trix::make('Graph 1 caption', 'matters_graph1_caption')->nullable(), + Text::make('Graph 2 image', 'matters_graph2_image')->nullable(), + Text::make('Graph 2 link', 'matters_graph2_link')->nullable(), + Trix::make('Graph 2 caption', 'matters_graph2_caption')->nullable(), + Text::make('Graph 3 image', 'matters_graph3_image')->nullable(), + Text::make('Graph 3 link', 'matters_graph3_link')->nullable(), + Trix::make('Graph 3 caption', 'matters_graph3_caption')->nullable(), + Trix::make('Paragraph 1', 'matters_paragraph_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Trix::make('Paragraph 2', 'matters_paragraph_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), ]; - $mattersFields[] = \Laravel\Nova\Fields\Heading::make('Other languages'); - $mattersFields = array_merge($mattersFields, $this->otherLocaleFields($locales, [ - ['label' => 'Matters title', 'key' => 'matters_title'], - ['label' => 'Matters paragraph 1', 'key' => 'matters_paragraph_1', 'textarea' => true, 'rich' => true], - ['label' => 'Matters paragraph 2', 'key' => 'matters_paragraph_2', 'textarea' => true, 'rich' => true], - ])); - - // — FAQ: English first, then other languages, then FAQ items + + // — FAQ: English only, then FAQ items $faqFields = [ Boolean::make('Use dynamic content for this section', 'faq_dynamic'), - \Laravel\Nova\Fields\Heading::make('English'), - Text::make('FAQ section title (English)', 'faq_title')->nullable(), + Text::make('FAQ section title', 'faq_title')->nullable(), ]; - $faqFields[] = \Laravel\Nova\Fields\Heading::make('Other languages'); - $faqFields = array_merge($faqFields, $this->otherLocaleFields($locales, [ - ['label' => 'FAQ title', 'key' => 'faq_title'], - ])); if (Schema::hasTable('girls_in_digital_faq_items')) { $faqFields[] = HasMany::make('FAQ items', 'faqItems', GirlsInDigitalFaqItem::class) ->fillUsing(function () { diff --git a/resources/views/static/girls-in-digital-week.blade.php b/resources/views/static/girls-in-digital-week.blade.php index 96fc22b18..9c6f45794 100644 --- a/resources/views/static/girls-in-digital-week.blade.php +++ b/resources/views/static/girls-in-digital-week.blade.php @@ -40,15 +40,17 @@ class="mb-4 max-w-full" src="/images/digital-girls/digital_girls_logo.svg" /> -

- {!! $content('landing_header') ?: "We're excited to announce Girls in Digital Week 2026! Empower, inspire and celebrate the next generation of girls and young Europeans!" !!} -

+
+ {!! $content('landing_header') !!} +
+ @if($heroDynamic && $page && $page->hero_video_url) @include('layout.video-player', [ 'id' => 'girls-digital-hero', - 'src' => ($heroDynamic && $page && $page->hero_video_url) ? $page->hero_video_url : 'https://www.youtube.com/embed/XfYqEYLbPWY?si=7JQaVoVM6bJLuuoT', + 'src' => $page->hero_video_url, ]) + @endif
-
+
+ @if($aboutDynamic && $page && $page->about_image)
- +
+ @endif

- {{ $content('about_girls_title') ?: 'About Girls in Digital' }} + {{ $content('about_girls_title') }}

-

- {!! $content('about_girls_description_1') ?: 'Get ready to celebrate Girls in Digital Week from 23–27 March 2026, as we put a spotlight on inclusion, innovation, and the limitless opportunities digital skills offer to all!' !!} -

-

- {!! $content('about_girls_description_2') ?: 'Girls in Digital encourages communities to get involved in meaningful ways. Through Girls Code It Better (GCIB) Sprints, educators and organisations can offer hands-on learning experiences where girls collaborate, build confidence, and solve real-world challenges using digital tools. The Female Role Model Database connects young people with women and gender-diverse professionals in STE(A)M, sharing stories and guidance that support their digital journeys. Together, these initiatives help turn curiosity into confidence and ideas into possibility.' !!} -

+
+ {!! $content('about_girls_description_1') !!} +
+
+ {!! $content('about_girls_description_2') !!} +
@if($b = $btn('gcib_sprint_hero'))
- @else - - Girls Code It Better Sprint -
- - -
-
@endif
@@ -126,14 +119,6 @@ class="w-full xl:w-auto flex justify-center items-center bg-primary hover:bg-hov > {{ $b->label }} - @else - - Female Role Models Database - @endif
@@ -145,14 +130,6 @@ class="w-full xl:w-auto flex justify-center items-center bg-primary hover:bg-hov > {{ $b->label }} - @else - - Open Call for GiD Challenges - @endif
@@ -174,63 +151,47 @@ class="animation-element move-background duration-[1.5s] absolute z-0 -bottom-28

- {{ $content('resource_title') ?: 'Resources' }} + {{ $content('resource_title') }}

- {{ $content('resource_person_title') ?: 'Are you a young person or parent?' }} + {{ $content('resource_person_title') }}

-

- {!! $content('resource_person_description_1') ?: 'You are a young person curious about technology, coding, or digital creativity; search for activities near you or connect with a role model through the Female Role Model Database. You are a parent seeking safe, inclusive digital activities; find opportunities nearby and explore the Female Role Model Database for inspiring role models.' !!} -

+
+ {!! $content('resource_person_description_1') !!} +

- {{ $content('resource_educator_title') ?: 'Are you an educator?' }} + {{ $content('resource_educator_title') }}

-

- {!! $content('resource_educator_description') ?: 'You are an educator looking to organise an activity to empower youth with digital skills in a safe and inclusive environment, where all feel welcomed to explore the endless opportunities that digital has to offer. Check our resources below for guidance and support in bringing your activity to life.' !!} -

+
+ {!! $content('resource_educator_description') !!} +
@@ -242,39 +203,49 @@ class="animation-element move-background duration-[1.5s] absolute z-0 -bottom-28

- {{ ($mattersDynamic && $page && $page->matters_title) ? $page->matters_title : 'Why Girls in Digital Matters' }} + {{ $mattersDynamic && $page ? $page->matters_title : '' }}

@php - $g1img = ($mattersDynamic && $page && $page->matters_graph1_image) ? $page->matters_graph1_image : '/images/digital-girls/fig-1.png'; - $g1link = ($mattersDynamic && $page && $page->matters_graph1_link) ? $page->matters_graph1_link : 'https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Young_people_-_digital_world'; + $g1img = ($mattersDynamic && $page && $page->matters_graph1_image) ? $page->matters_graph1_image : ''; + $g1link = ($mattersDynamic && $page && $page->matters_graph1_link) ? $page->matters_graph1_link : '#'; @endphp + @if($g1img) - {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph1_caption') : 'Young people – digital world. Eurostat 2023' }} + {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph1_caption') : '' }} + @endif @php - $g2img = ($mattersDynamic && $page && $page->matters_graph2_image) ? $page->matters_graph2_image : '/images/digital-girls/fig-2.png'; - $g2link = ($mattersDynamic && $page && $page->matters_graph2_link) ? $page->matters_graph2_link : 'https://ec.europa.eu/eurostat/statistics-explained/index.php?title=ICT_specialists_in_employment#Explore_further'; + $g2img = ($mattersDynamic && $page && $page->matters_graph2_image) ? $page->matters_graph2_image : ''; + $g2link = ($mattersDynamic && $page && $page->matters_graph2_link) ? $page->matters_graph2_link : '#'; @endphp + @if($g2img) - {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph2_caption') : 'ICT specialists in employment. Eurostat 2023' }} + {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph2_caption') : '' }} -

- {!! ($mattersDynamic && $page && $page->matters_paragraph_1) ? $page->matters_paragraph_1 : __('girls-in-digital.relevant_statistics_graph_1') !!} -

+ @endif + @if($mattersDynamic && $page && $page->matters_paragraph_1) +
+ {!! $page->matters_paragraph_1 !!} +
+ @endif
@php - $g3img = ($mattersDynamic && $page && $page->matters_graph3_image) ? $page->matters_graph3_image : '/images/digital-girls/fig-3.png'; - $g3link = ($mattersDynamic && $page && $page->matters_graph3_link) ? $page->matters_graph3_link : 'https://unesdoc.unesco.org/ark:/48223/pf0000253479'; + $g3img = ($mattersDynamic && $page && $page->matters_graph3_image) ? $page->matters_graph3_image : ''; + $g3link = ($mattersDynamic && $page && $page->matters_graph3_link) ? $page->matters_graph3_link : '#'; @endphp + @if($g3img) - {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph3_caption') : 'Cracking the code: Girls and women education in STEM. UNESCO, 2017.' }} + {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph3_caption') : '' }} -

- {!! ($mattersDynamic && $page && $page->matters_paragraph_2) ? $page->matters_paragraph_2 : __('girls-in-digital.relevant_statistics_graph_2') !!} -

+ @endif + @if($mattersDynamic && $page && $page->matters_paragraph_2) +
+ {!! $page->matters_paragraph_2 !!} +
+ @endif
@@ -287,7 +258,7 @@ class="animation-element move-background duration-[1.5s] absolute z-0 -bottom-28

- {{ ($faqDynamic && $page && $page->faq_title) ? $page->faq_title : 'FAQ\'s' }} + {{ ($faqDynamic && $page && $page->faq_title) ? $page->faq_title : '' }}