diff --git a/app/GirlsInDigitalButton.php b/app/GirlsInDigitalButton.php deleted file mode 100644 index 3f9f46903..000000000 --- a/app/GirlsInDigitalButton.php +++ /dev/null @@ -1,35 +0,0 @@ - 'boolean', - 'enabled' => 'boolean', - 'position' => 'integer', - ]; - - public function scopeEnabled($query) - { - return $query->where('enabled', true); - } - - public function scopeOrdered($query) - { - return $query->orderBy('position')->orderBy('id'); - } -} diff --git a/app/GirlsInDigitalPage.php b/app/GirlsInDigitalPage.php index 6f3fb8552..4453c248b 100644 --- a/app/GirlsInDigitalPage.php +++ b/app/GirlsInDigitalPage.php @@ -3,14 +3,34 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; class GirlsInDigitalPage extends Model { protected $table = 'girls_in_digital_page'; - protected $fillable = ['locale_overrides']; + protected $fillable = [ + 'use_dynamic_content', + 'hero_intro', + 'hero_video_url', + 'about_title', + 'about_description_1', + 'about_description_2', + 'resource_title', + 'resource_person_title', + 'resource_person_description_1', + 'resource_person_description_2', + 'resource_educator_title', + 'resource_educator_description', + 'buttons', + 'locale_overrides', + ]; - protected $casts = ['locale_overrides' => 'array']; + protected $casts = [ + 'use_dynamic_content' => 'boolean', + 'buttons' => 'array', + 'locale_overrides' => 'array', + ]; /** * Get the singleton page config (id = 1). Create if missing. @@ -25,7 +45,26 @@ public static function config(): self } /** - * Get content for a key in the current locale: override or lang fallback. + * Content keys that have a main (default/English) column on the model. + */ + public static function contentKeys(): array + { + return [ + 'hero_intro', + 'about_title', + 'about_description_1', + 'about_description_2', + 'resource_title', + 'resource_person_title', + 'resource_person_description_1', + 'resource_person_description_2', + 'resource_educator_title', + 'resource_educator_description', + ]; + } + + /** + * Get content for a key in the current locale: locale override, then main (English) column, then lang file. */ public function contentForLocale(string $key, ?string $locale = null): string { @@ -34,6 +73,53 @@ public function contentForLocale(string $key, ?string $locale = null): string if (! empty($overrides[$locale][$key])) { return (string) $overrides[$locale][$key]; } + if (in_array($key, self::contentKeys(), true)) { + $value = $this->getAttribute($key); + if ($value !== null && $value !== '') { + return (string) $value; + } + } return (string) __('girls-in-digital.' . $key); } + + /** + * Get a button by key. Returns stdClass with label, url, open_new_tab, enabled or null. + */ + public function getButton(string $key, ?string $locale = null): ?object + { + $buttons = $this->getButtonsForLocale($locale); + $btn = $buttons->firstWhere('key', $key); + if (! $btn || empty($btn['enabled'])) { + return null; + } + $o = new \stdClass; + $o->key = $btn['key']; + $o->label = $btn['label'] ?? ''; + $o->url = $btn['url'] ?? '#'; + $o->open_new_tab = ! empty($btn['open_new_tab']); + $o->enabled = true; + return $o; + } + + /** + * Buttons for locale: merge locale_overrides[locale].buttons onto main buttons. + */ + public function getButtonsForLocale(?string $locale = null): Collection + { + $locale = $locale ?? app()->getLocale(); + $main = collect($this->buttons ?? []); + $overrides = $this->locale_overrides ?? []; + $localeButtons = $overrides[$locale]['buttons'] ?? null; + if (! is_array($localeButtons)) { + return $main; + } + $byKey = $main->keyBy('key'); + foreach ($localeButtons as $b) { + $k = $b['key'] ?? null; + if ($k !== null) { + $byKey->put($k, array_merge($byKey->get($k) ?? [], $b)); + } + } + return $byKey->values()->sortBy('position')->values(); + } } diff --git a/app/Http/View/Composers/GirlsInDigitalComposer.php b/app/Http/View/Composers/GirlsInDigitalComposer.php index 8df47868d..c3df63115 100644 --- a/app/Http/View/Composers/GirlsInDigitalComposer.php +++ b/app/Http/View/Composers/GirlsInDigitalComposer.php @@ -2,7 +2,6 @@ namespace App\Http\View\Composers; -use App\GirlsInDigitalButton; use App\GirlsInDigitalPage; use Illuminate\Support\Facades\Schema; use Illuminate\View\View; @@ -11,11 +10,7 @@ class GirlsInDigitalComposer { public function compose(View $view): void { - $buttons = collect(); - if (Schema::hasTable('girls_in_digital_buttons')) { - $buttons = GirlsInDigitalButton::enabled()->ordered()->get(); - } $page = Schema::hasTable('girls_in_digital_page') ? GirlsInDigitalPage::config() : null; - $view->with(compact('buttons', 'page')); + $view->with(compact('page')); } } diff --git a/app/Nova/GirlsInDigitalButton.php b/app/Nova/GirlsInDigitalButton.php deleted file mode 100644 index 416ec6fec..000000000 --- a/app/Nova/GirlsInDigitalButton.php +++ /dev/null @@ -1,57 +0,0 @@ -sortable(), - Text::make('Key', 'key') - ->rules('required') - ->help('Unique identifier, e.g. gcib_sprint_hero. Used in the blade to place the button.'), - Text::make('Label', 'label')->rules('required'), - Text::make('URL', 'url')->rules('required')->hideFromIndex(), - Boolean::make('Open in new tab', 'open_new_tab'), - Boolean::make('Enabled', 'enabled') - ->help('When disabled, this button is hidden on the Girls in Digital page.'), - Number::make('Position', 'position')->min(0)->default(0), - ]; - } - - public static function indexQuery(NovaRequest $request, $query) - { - return $query->orderBy('position')->orderBy('id'); - } -} diff --git a/app/Nova/GirlsInDigitalPage.php b/app/Nova/GirlsInDigitalPage.php index 338d2f3fc..8b23e64ca 100644 --- a/app/Nova/GirlsInDigitalPage.php +++ b/app/Nova/GirlsInDigitalPage.php @@ -3,8 +3,11 @@ namespace App\Nova; use Illuminate\Http\Request; +use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\Code; use Laravel\Nova\Fields\ID; +use Laravel\Nova\Fields\Text; +use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Panel; @@ -18,7 +21,7 @@ class GirlsInDigitalPage extends Resource public static function label() { - return 'Girls in Digital – Page content'; + return 'Girls in Digital'; } public static function singularLabel() @@ -36,6 +39,12 @@ public static function uriKey(): string return 'girls-in-digital-page'; } + /** Hide from index – single resource, edit from detail. */ + public static function indexQuery(NovaRequest $request, $query) + { + return $query->where('id', 1); + } + private static function localesSorted(): array { $locales = config('app.locales', ['en']); @@ -50,43 +59,19 @@ private static function localesSorted(): array return $locales; } - /** Content keys that can be overridden per locale (from resources/lang/xx/girls-in-digital.php). */ - public static function contentKeys(): array - { - return [ - 'landing_header', - 'about_girls_title', - 'about_girls_description_1', - 'about_girls_description_2', - 'resource_title', - 'resource_person_title', - 'resource_person_description_1', - 'resource_person_description_2', - 'resource_educator_title', - 'resource_educator_description', - 'resource_search_activity', - 'resource_organise_activity', - 'resource_digital_activity', - 'resource_social_media', - ]; - } - public function fields(Request $request): array { $locales = self::localesSorted(); - $keysHelp = 'Optional keys: ' . implode(', ', self::contentKeys()); - $localePanels = []; foreach ($locales as $locale) { $localePanels[] = new Panel('Override: ' . strtoupper($locale), [ Code::make('[' . $locale . ']', 'locale_override_' . $locale) ->json() ->nullable() - ->help($keysHelp) + ->help('Optional. Override text/buttons for this locale. Keys: ' . implode(', ', \App\GirlsInDigitalPage::contentKeys()) . '. For buttons use "buttons": [{"key":"gcib_sprint_hero","label":"...","url":"...","open_new_tab":false,"enabled":true,"position":0}].') ->resolveUsing(function () use ($locale) { $overrides = $this->resource->locale_overrides ?? []; - $data = $overrides[$locale] ?? []; - return $data; + return $overrides[$locale] ?? []; }) ->fillUsing(function ($request, $model, $attribute, $requestAttribute) { $locale = str_replace('locale_override_', '', $attribute); @@ -100,8 +85,43 @@ public function fields(Request $request): array return [ ID::make()->onlyOnForms(), - new Panel('Per-locale content overrides (optional)', [ - \Laravel\Nova\Fields\Heading::make('Expand a locale below to override text for that language. Defaults come from resources/lang/{locale}/girls-in-digital.php.'), + + Boolean::make('Use dynamic content', 'use_dynamic_content') + ->help('When on, the Girls in Digital page uses the content below. When off, the static blade content is shown (current hardcoded text/images). Defaults to English for all languages; use locale overrides below for other languages.'), + + new Panel('Hero', [ + Textarea::make('Hero intro', 'hero_intro') + ->nullable() + ->help('Default (English) hero text. Leave empty to use static/lang.'), + Text::make('Hero video URL', 'hero_video_url') + ->nullable() + ->help('YouTube embed URL, e.g. https://www.youtube.com/embed/...'), + ]), + + new Panel('About', [ + Text::make('About title', 'about_title')->nullable(), + Textarea::make('About description 1', 'about_description_1')->nullable(), + Textarea::make('About description 2', 'about_description_2')->nullable()->help('HTML allowed.'), + ]), + + new Panel('Resources', [ + Text::make('Resources title', 'resource_title')->nullable(), + Text::make('Young person / parent title', 'resource_person_title')->nullable(), + Textarea::make('Young person / parent description 1', 'resource_person_description_1')->nullable(), + Textarea::make('Young person / parent description 2', 'resource_person_description_2')->nullable(), + Text::make('Educator title', 'resource_educator_title')->nullable(), + Textarea::make('Educator description', 'resource_educator_description')->nullable(), + ]), + + new Panel('Buttons', [ + Code::make('Buttons', 'buttons') + ->json() + ->nullable() + ->help('Array of buttons. Each: {"key":"gcib_sprint_hero","label":"Girls Code It Better Sprint","url":"https://...","open_new_tab":false,"enabled":true,"position":0}. Keys: gcib_sprint_hero, female_role_models, open_call_challenges, search_activity, meet_role_model, organise_gcib_sprint, activity_guideline, social_media_kit. Disabled buttons are hidden.'), + ]), + + new Panel('Per-locale overrides (optional)', [ + \Laravel\Nova\Fields\Heading::make('Expand a locale to override text or button labels for that language. Defaults to English for all.'), ...$localePanels, ]), ]; diff --git a/database/migrations/2026_02_09_200000_create_girls_in_digital_buttons_table.php b/database/migrations/2026_02_09_200000_create_girls_in_digital_buttons_table.php deleted file mode 100644 index 5ad8cbcc4..000000000 --- a/database/migrations/2026_02_09_200000_create_girls_in_digital_buttons_table.php +++ /dev/null @@ -1,27 +0,0 @@ -id(); - $table->string('key')->unique(); - $table->string('label'); - $table->string('url'); - $table->boolean('open_new_tab')->default(false); - $table->boolean('enabled')->default(true); - $table->unsignedInteger('position')->default(0); - $table->timestamps(); - }); - } - - public function down(): void - { - Schema::dropIfExists('girls_in_digital_buttons'); - } -}; diff --git a/database/migrations/2026_02_09_210000_consolidate_girls_in_digital_to_single_page.php b/database/migrations/2026_02_09_210000_consolidate_girls_in_digital_to_single_page.php new file mode 100644 index 000000000..80eeb4b9e --- /dev/null +++ b/database/migrations/2026_02_09_210000_consolidate_girls_in_digital_to_single_page.php @@ -0,0 +1,84 @@ +boolean('use_dynamic_content')->default(false)->after('id'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'hero_intro')) { + $table->text('hero_intro')->nullable()->after('use_dynamic_content'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'hero_video_url')) { + $table->string('hero_video_url')->nullable()->after('hero_intro'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'about_title')) { + $table->string('about_title')->nullable()->after('hero_video_url'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'about_description_1')) { + $table->text('about_description_1')->nullable()->after('about_title'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'about_description_2')) { + $table->text('about_description_2')->nullable()->after('about_description_1'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'resource_title')) { + $table->string('resource_title')->nullable()->after('about_description_2'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'resource_person_title')) { + $table->string('resource_person_title')->nullable()->after('resource_title'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'resource_person_description_1')) { + $table->text('resource_person_description_1')->nullable()->after('resource_person_title'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'resource_person_description_2')) { + $table->text('resource_person_description_2')->nullable()->after('resource_person_description_1'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'resource_educator_title')) { + $table->string('resource_educator_title')->nullable()->after('resource_person_description_2'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'resource_educator_description')) { + $table->text('resource_educator_description')->nullable()->after('resource_educator_title'); + } + if (! Schema::hasColumn('girls_in_digital_page', 'buttons')) { + $table->json('buttons')->nullable()->after('resource_educator_description'); + } + }); + + if (Schema::hasTable('girls_in_digital_buttons')) { + $rows = DB::table('girls_in_digital_buttons')->orderBy('position')->orderBy('id')->get(); + $buttons = $rows->map(fn ($r) => [ + 'key' => $r->key, + 'label' => $r->label, + 'url' => $r->url, + 'open_new_tab' => (bool) $r->open_new_tab, + 'enabled' => (bool) $r->enabled, + 'position' => (int) $r->position, + ])->values()->all(); + DB::table('girls_in_digital_page')->where('id', 1)->update(['buttons' => json_encode($buttons)]); + Schema::dropIfExists('girls_in_digital_buttons'); + } + } + + public function down(): void + { + Schema::table('girls_in_digital_page', function (Blueprint $table) { + $cols = ['use_dynamic_content', 'hero_intro', 'hero_video_url', 'about_title', 'about_description_1', 'about_description_2', 'resource_title', 'resource_person_title', 'resource_person_description_1', 'resource_person_description_2', 'resource_educator_title', 'resource_educator_description', 'buttons']; + foreach ($cols as $col) { + if (Schema::hasColumn('girls_in_digital_page', $col)) { + $table->dropColumn($col); + } + } + }); + } +}; diff --git a/database/seeders/GirlsInDigitalButtonSeeder.php b/database/seeders/GirlsInDigitalButtonSeeder.php index a9ececc6e..9320c5b3c 100644 --- a/database/seeders/GirlsInDigitalButtonSeeder.php +++ b/database/seeders/GirlsInDigitalButtonSeeder.php @@ -2,35 +2,36 @@ namespace Database\Seeders; -use App\GirlsInDigitalButton; +use App\GirlsInDigitalPage; use Illuminate\Database\Seeder; class GirlsInDigitalButtonSeeder extends Seeder { + /** + * Seed the Girls in Digital page with default buttons (and optional default text). + * Run after the consolidate migration. Safe to run multiple times. + */ public function run(): void { - $defaults = [ - ['key' => 'gcib_sprint_hero', 'label' => 'Girls Code It Better Sprint', 'url' => 'https://codeweek.eu/blog/girls-in-digital-week-2026/', 'open_new_tab' => false, 'position' => 0], - ['key' => 'female_role_models', 'label' => 'Female Role Models Database', 'url' => 'https://codeweek.ecwt.eu/', 'open_new_tab' => true, 'position' => 1], - ['key' => 'open_call_challenges', 'label' => 'Open Call for GiD Challenges', 'url' => '/docs/girls-in-digital/open-call-for-new-code-week-challenges_v2.pdf', 'open_new_tab' => true, 'position' => 2], - ['key' => 'search_activity', 'label' => 'Search an activity', 'url' => '/events', 'open_new_tab' => false, 'position' => 3], - ['key' => 'meet_role_model', 'label' => 'Meet a Role Model', 'url' => 'https://codeweek.ecwt.eu/role-models/', 'open_new_tab' => true, 'position' => 4], - ['key' => 'organise_gcib_sprint', 'label' => 'Organise a GCIB Sprint', 'url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/GCIB-Sprint-materials.zip', 'open_new_tab' => false, 'position' => 5], - ['key' => 'activity_guideline', 'label' => 'Girls in Digital Activity Guideline', 'url' => '/docs/girls-in-digital/girls-in-digital-activity-guidelines.pdf', 'open_new_tab' => true, 'position' => 6], - ['key' => 'social_media_kit', 'label' => 'Social Media Kit', 'url' => '/docs/girls-in-digital/girls-in-digital-media-kit.pdf', 'open_new_tab' => true, 'position' => 7], + $page = GirlsInDigitalPage::first(); + if (! $page) { + return; + } + + $defaultButtons = [ + ['key' => 'gcib_sprint_hero', 'label' => 'Girls Code It Better Sprint', 'url' => 'https://codeweek.eu/blog/girls-in-digital-week-2026/', 'open_new_tab' => false, 'enabled' => true, 'position' => 0], + ['key' => 'female_role_models', 'label' => 'Female Role Models Database', 'url' => 'https://codeweek.ecwt.eu/', 'open_new_tab' => true, 'enabled' => true, 'position' => 1], + ['key' => 'open_call_challenges', 'label' => 'Open Call for GiD Challenges', 'url' => '/docs/girls-in-digital/open-call-for-new-code-week-challenges_v2.pdf', 'open_new_tab' => true, 'enabled' => true, 'position' => 2], + ['key' => 'search_activity', 'label' => 'Search an activity', 'url' => '/events', 'open_new_tab' => false, 'enabled' => true, 'position' => 3], + ['key' => 'meet_role_model', 'label' => 'Meet a Role Model', 'url' => 'https://codeweek.ecwt.eu/role-models/', 'open_new_tab' => true, 'enabled' => true, 'position' => 4], + ['key' => 'organise_gcib_sprint', 'label' => 'Organise a GCIB Sprint', 'url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/GCIB-Sprint-materials.zip', 'open_new_tab' => false, 'enabled' => true, 'position' => 5], + ['key' => 'activity_guideline', 'label' => 'Girls in Digital Activity Guideline', 'url' => '/docs/girls-in-digital/girls-in-digital-activity-guidelines.pdf', 'open_new_tab' => true, 'enabled' => true, 'position' => 6], + ['key' => 'social_media_kit', 'label' => 'Social Media Kit', 'url' => '/docs/girls-in-digital/girls-in-digital-media-kit.pdf', 'open_new_tab' => true, 'enabled' => true, 'position' => 7], ]; - foreach ($defaults as $i => $row) { - GirlsInDigitalButton::updateOrCreate( - ['key' => $row['key']], - [ - 'label' => $row['label'], - 'url' => $row['url'], - 'open_new_tab' => $row['open_new_tab'], - 'enabled' => true, - 'position' => $row['position'], - ] - ); - } + $page->buttons = $defaultButtons; + $page->save(); + + $this->command->info('Girls in Digital page updated with default buttons. Edit in Nova under Content → Girls in Digital.'); } } diff --git a/resources/views/static/girls-in-digital-week.blade.php b/resources/views/static/girls-in-digital-week.blade.php index 668a22f39..8dfe8ba10 100644 --- a/resources/views/static/girls-in-digital-week.blade.php +++ b/resources/views/static/girls-in-digital-week.blade.php @@ -10,12 +10,18 @@ @endsection @php - $btn = function($key) use ($buttons) { - if (!isset($buttons) || $buttons->isEmpty()) { return null; } - return $buttons->keyBy('key')->get($key); + $useDynamic = $page && $page->use_dynamic_content; + $btn = function($key) use ($page, $useDynamic) { + if (!$useDynamic) { + return null; + } + return $page ? $page->getButton($key) : null; }; - $content = function($key) use ($page) { - return $page ? $page->contentForLocale($key) : (__('girls-in-digital.' . $key) ?: ''); + $content = function($key) use ($page, $useDynamic) { + if (!$useDynamic || !$page) { + return ''; + } + return $page->contentForLocale($key); }; @endphp @section('content') @@ -30,14 +36,17 @@ class="mb-4 max-w-full" src="/images/digital-girls/digital_girls_logo.svg" />
- We’re excited to announce Girls in Digital Week 2026! - Empower, inspire and celebrate the next generation of girls and young Europeans! + @if($useDynamic && $page->hero_intro) + {!! $page->hero_intro !!} + @else + {{ $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!" }} + @endif