diff --git a/app/GirlsInDigitalFaqItem.php b/app/GirlsInDigitalFaqItem.php new file mode 100644 index 000000000..8cb290d80 --- /dev/null +++ b/app/GirlsInDigitalFaqItem.php @@ -0,0 +1,59 @@ +page_id ?: (request()->query('viaResourceId') ?? 1); + $item->page_id = (int) $pageId; + if ($item->position === null || $item->position === 0) { + $max = self::where('page_id', $item->page_id)->max('position'); + $item->position = $max === null ? 0 : (int) $max + 1; + } + }); + } + protected $table = 'girls_in_digital_faq_items'; + + protected $fillable = [ + 'page_id', + 'position', + 'question', + 'answer', + 'locale_overrides', + ]; + + protected $casts = [ + 'position' => 'integer', + 'locale_overrides' => 'array', + ]; + + public function page() + { + return $this->belongsTo(GirlsInDigitalPage::class, 'page_id'); + } + + public function questionForLocale(?string $locale = null): string + { + $locale = $locale ?? app()->getLocale(); + $overrides = $this->locale_overrides ?? []; + if (! empty($overrides[$locale]['question'])) { + return (string) $overrides[$locale]['question']; + } + return (string) ($this->question ?? ''); + } + + public function answerForLocale(?string $locale = null): string + { + $locale = $locale ?? app()->getLocale(); + $overrides = $this->locale_overrides ?? []; + if (! empty($overrides[$locale]['answer'])) { + return (string) $overrides[$locale]['answer']; + } + return (string) ($this->answer ?? ''); + } +} diff --git a/app/GirlsInDigitalPage.php b/app/GirlsInDigitalPage.php index 36bc6eebb..54c1d61cc 100644 --- a/app/GirlsInDigitalPage.php +++ b/app/GirlsInDigitalPage.php @@ -51,7 +51,6 @@ class GirlsInDigitalPage extends Model 'matters_paragraph_1', 'matters_paragraph_2', 'faq_title', - 'faq_items', 'locale_overrides', ]; @@ -61,7 +60,6 @@ class GirlsInDigitalPage extends Model 'resources_dynamic' => 'boolean', 'matters_dynamic' => 'boolean', 'faq_dynamic' => 'boolean', - 'faq_items' => 'array', 'locale_overrides' => 'array', ]; @@ -70,6 +68,11 @@ public function buttons() return $this->hasMany(GirlsInDigitalButton::class, 'page_id')->orderBy('position'); } + public function faqItems() + { + return $this->hasMany(GirlsInDigitalFaqItem::class, 'page_id')->orderBy('position'); + } + /** * Get the singleton page config (id = 1). Create if missing. */ @@ -170,17 +173,13 @@ public function getButtonsForLocale(?string $locale = null): Collection } /** - * FAQ items for locale: locale_overrides[locale].faq_items or main faq_items. - * Each item: ['question' => string, 'answer' => string]. + * FAQ items for locale: returns array of ['question' => string, 'answer' => string] from faqItems relationship. */ public function faqItemsForLocale(?string $locale = null): array { - $locale = $locale ?? app()->getLocale(); - $overrides = $this->locale_overrides ?? []; - if (! empty($overrides[$locale]['faq_items']) && is_array($overrides[$locale]['faq_items'])) { - return $overrides[$locale]['faq_items']; - } - $items = $this->faq_items ?? []; - return is_array($items) ? $items : []; + return $this->faqItems->map(fn (GirlsInDigitalFaqItem $item) => [ + 'question' => $item->questionForLocale($locale), + 'answer' => $item->answerForLocale($locale), + ])->all(); } } diff --git a/app/Nova/GirlsInDigitalFaqItem.php b/app/Nova/GirlsInDigitalFaqItem.php new file mode 100644 index 000000000..40d6cc61a --- /dev/null +++ b/app/Nova/GirlsInDigitalFaqItem.php @@ -0,0 +1,120 @@ +nullable() + ->resolveUsing(function () use ($locale) { + $overrides = $this->resource->locale_overrides ?? []; + return $overrides[$locale]['question'] ?? ''; + }) + ->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale) { + $value = $request->get($requestAttribute); + $overrides = $model->locale_overrides ?? []; + if (! isset($overrides[$locale])) { + $overrides[$locale] = []; + } + $overrides[$locale]['question'] = $value; + $model->locale_overrides = $overrides; + }); + $translationFields[] = Trix::make('Answer (' . strtoupper($locale) . ')', 'locale_' . $locale . '_answer') + ->nullable() + ->resolveUsing(function () use ($locale) { + $overrides = $this->resource->locale_overrides ?? []; + return $overrides[$locale]['answer'] ?? ''; + }) + ->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale) { + $value = $request->get($requestAttribute); + $overrides = $model->locale_overrides ?? []; + if (! isset($overrides[$locale])) { + $overrides[$locale] = []; + } + $overrides[$locale]['answer'] = $value; + $model->locale_overrides = $overrides; + }); + } + + $fields = [ + ID::make()->onlyOnForms(), + \Laravel\Nova\Fields\Hidden::make('Page', 'page_id') + ->default(fn ($request) => $request->viaResourceId ?? 1), + Text::make('Question (default)', 'question')->nullable()->rules('nullable', 'string'), + Trix::make('Answer (default)', 'answer')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + \Laravel\Nova\Fields\Number::make('Order', 'position')->min(0)->help('Lower numbers appear first.'), + ]; + + if (count($translationFields) > 0) { + $fields[] = new Panel('Translations', $translationFields); + } + + return $fields; + } + + public static function indexQuery(NovaRequest $request, $query) + { + return $query->orderBy('position'); + } + + public static function relatableQuery(NovaRequest $request, $query) + { + return $query->orderBy('position'); + } +} diff --git a/app/Nova/GirlsInDigitalPage.php b/app/Nova/GirlsInDigitalPage.php index 854629be9..110c6f1c9 100644 --- a/app/Nova/GirlsInDigitalPage.php +++ b/app/Nova/GirlsInDigitalPage.php @@ -4,11 +4,13 @@ use App\GirlsInDigitalButton; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Schema; use Laravel\Nova\Fields\Boolean; -use Laravel\Nova\Fields\Code; +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; @@ -20,21 +22,36 @@ class GirlsInDigitalPage extends Resource public static $title = 'id'; - /** Button keys for the 8 fixed buttons (same order as blade). */ - private static function buttonKeys(): array + /** Button key => human title. Keys by section: Hero, About, Resources. */ + private static function buttonKeysBySection(): array { return [ - 'gcib_sprint_hero' => 'Girls Code It Better Sprint', - 'female_role_models' => 'Female Role Models Database', - 'open_call_challenges' => 'Open Call for GiD Challenges', - 'search_activity' => 'Search an activity', - 'meet_role_model' => 'Meet a Role Model', - 'organise_gcib_sprint' => 'Organise a GCIB Sprint', - 'activity_guideline' => 'Girls in Digital Activity Guideline', - 'social_media_kit' => 'Social Media Kit', + 'hero' => [ + 'gcib_sprint_hero' => 'Girls Code It Better Sprint', + ], + 'about' => [ + 'female_role_models' => 'Female Role Models Database', + 'open_call_challenges' => 'Open Call for GiD Challenges', + ], + 'resources' => [ + 'search_activity' => 'Search an activity', + 'meet_role_model' => 'Meet a Role Model', + 'organise_gcib_sprint' => 'Organise a GCIB Sprint', + 'activity_guideline' => 'Girls in Digital Activity Guideline', + 'social_media_kit' => 'Social Media Kit', + ], ]; } + private static function allButtonKeys(): array + { + $out = []; + foreach (self::buttonKeysBySection() as $keys) { + $out = array_merge($out, array_keys($keys)); + } + return $out; + } + public static function label() { return 'Girls in Digital'; @@ -55,7 +72,6 @@ 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); @@ -75,114 +91,174 @@ private static function localesSorted(): array 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) { + $overrides = $this->resource->locale_overrides ?? []; + return $overrides[$locale][$key] ?? ''; + }); + $field->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) { + $value = $request->get($requestAttribute); + $overrides = $model->locale_overrides ?? []; + if (! isset($overrides[$locale])) { + $overrides[$locale] = []; + } + $overrides[$locale][$key] = $value; + $model->locale_overrides = $overrides; + }); + return $field; + } + + /** Build the 4 fields for one button (enabled, url, label, open_new_tab). */ + private function buttonFields(string $key, string $title): array + { + return [ + Boolean::make($title . ' — Enabled', 'button_' . $key . '_enabled') + ->resolveUsing(fn () => $this->getButtonField($key, 'enabled')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'enabled', $r->get($ra))), + Text::make($title . ' — Link (URL)', 'button_' . $key . '_url') + ->nullable() + ->resolveUsing(fn () => $this->getButtonField($key, 'url')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'url', $r->get($ra))), + Text::make($title . ' — Text (label)', 'button_' . $key . '_label') + ->nullable() + ->resolveUsing(fn () => $this->getButtonField($key, 'label')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'label', $r->get($ra))), + Boolean::make($title . ' — Open in new window', 'button_' . $key . '_open_new_tab') + ->resolveUsing(fn () => $this->getButtonField($key, 'open_new_tab')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'open_new_tab', $r->get($ra))), + ]; + } + public function fields(Request $request): array { $locales = self::localesSorted(); - $localePanels = []; + + $heroFields = [ + Boolean::make('Use dynamic content for this section', 'hero_dynamic') + ->help('When on, hero uses the content below.'), + Trix::make('Hero intro (default)', 'hero_intro')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Hero video URL (default)', 'hero_video_url')->nullable()->help('YouTube embed URL.'), + Text::make('Hero image (default)', 'hero_image')->nullable(), + ]; + foreach ($locales as $locale) { + if ($locale === 'en') { + continue; + } + $heroFields[] = $this->localeField('Hero intro (' . strtoupper($locale) . ')', $locale, 'hero_intro', true, true); + $heroFields[] = $this->localeField('Hero video URL (' . strtoupper($locale) . ')', $locale, 'hero_video_url', false); + } + foreach (self::buttonKeysBySection()['hero'] as $key => $title) { + $heroFields = array_merge($heroFields, $this->buttonFields($key, $title)); + } + + $aboutFields = [ + Boolean::make('Use dynamic content for this section', 'about_dynamic'), + Text::make('About title (default)', 'about_title')->nullable(), + Trix::make('About description 1 (default)', 'about_description_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Trix::make('About description 2 (default)', 'about_description_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('About image (default)', 'about_image')->nullable(), + ]; foreach ($locales as $locale) { - $localePanels[] = new Panel('Override: ' . strtoupper($locale), [ - Code::make('[' . $locale . ']', 'locale_override_' . $locale) - ->json() - ->nullable() - ->help('Optional. Override text for this locale. Keys: ' . implode(', ', \App\GirlsInDigitalPage::contentKeys()) . '. faq_items: [{"question":"...","answer":"..."}].') - ->resolveUsing(function () use ($locale) { - $overrides = $this->resource->locale_overrides ?? []; - return $overrides[$locale] ?? []; - }) - ->fillUsing(function ($request, $model, $attribute, $requestAttribute) { - $locale = str_replace('locale_override_', '', $attribute); - $value = $request->get($requestAttribute); - $overrides = $model->locale_overrides ?? []; - $overrides[$locale] = is_string($value) ? (json_decode($value, true) ?? []) : (is_array($value) ? $value : []); - $model->locale_overrides = $overrides; - }), - ]); - } - - $buttonPanels = []; - foreach (self::buttonKeys() as $key => $title) { - $buttonPanels[] = new Panel('Button: ' . $title, [ - Boolean::make('Enabled', 'button_' . $key . '_enabled') - ->resolveUsing(fn () => $this->getButtonField($key, 'enabled')) - ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'enabled', $r->get($ra))), - Text::make('Link (URL)', 'button_' . $key . '_url') - ->nullable() - ->resolveUsing(fn () => $this->getButtonField($key, 'url')) - ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'url', $r->get($ra))), - Text::make('Text (label)', 'button_' . $key . '_label') - ->nullable() - ->resolveUsing(fn () => $this->getButtonField($key, 'label')) - ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'label', $r->get($ra))), - Boolean::make('Open in new window', 'button_' . $key . '_open_new_tab') - ->resolveUsing(fn () => $this->getButtonField($key, 'open_new_tab')) - ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'open_new_tab', $r->get($ra))), - ]); + if ($locale === 'en') { + continue; + } + $aboutFields[] = $this->localeField('About title (' . strtoupper($locale) . ')', $locale, 'about_title', false); + $aboutFields[] = $this->localeField('About description 1 (' . strtoupper($locale) . ')', $locale, 'about_description_1', true, true); + $aboutFields[] = $this->localeField('About description 2 (' . strtoupper($locale) . ')', $locale, 'about_description_2', true, true); + } + foreach (self::buttonKeysBySection()['about'] as $key => $title) { + $aboutFields = array_merge($aboutFields, $this->buttonFields($key, $title)); + } + + $resourcesFields = [ + Boolean::make('Use dynamic content for this section', 'resources_dynamic'), + Text::make('Resources title (default)', 'resource_title')->nullable(), + Text::make('Young person / parent title (default)', 'resource_person_title')->nullable(), + Trix::make('Young person / parent description 1 (default)', 'resource_person_description_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Trix::make('Young person / parent description 2 (default)', 'resource_person_description_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Young person / parent image (default)', 'resource_young_image')->nullable(), + Text::make('Educator title (default)', 'resource_educator_title')->nullable(), + Trix::make('Educator description (default)', 'resource_educator_description')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Text::make('Educator image (default)', 'resource_educator_image')->nullable(), + ]; + foreach ($locales as $locale) { + if ($locale === 'en') { + continue; + } + $resourcesFields[] = $this->localeField('Resource title (' . strtoupper($locale) . ')', $locale, 'resource_title', false); + $resourcesFields[] = $this->localeField('Young person title (' . strtoupper($locale) . ')', $locale, 'resource_person_title', false); + $resourcesFields[] = $this->localeField('Young person description 1 (' . strtoupper($locale) . ')', $locale, 'resource_person_description_1', true, true); + $resourcesFields[] = $this->localeField('Young person description 2 (' . strtoupper($locale) . ')', $locale, 'resource_person_description_2', true, true); + $resourcesFields[] = $this->localeField('Educator title (' . strtoupper($locale) . ')', $locale, 'resource_educator_title', false); + $resourcesFields[] = $this->localeField('Educator description (' . strtoupper($locale) . ')', $locale, 'resource_educator_description', true, true); + } + foreach (self::buttonKeysBySection()['resources'] as $key => $title) { + $resourcesFields = array_merge($resourcesFields, $this->buttonFields($key, $title)); + } + + $mattersFields = [ + Boolean::make('Use dynamic content for this section', 'matters_dynamic'), + Text::make('Section title (default)', 'matters_title')->nullable(), + Text::make('Graph 1 image (default)', 'matters_graph1_image')->nullable(), + Text::make('Graph 1 link (default)', 'matters_graph1_link')->nullable(), + Trix::make('Graph 1 caption (default)', 'matters_graph1_caption')->nullable(), + Text::make('Graph 2 image (default)', 'matters_graph2_image')->nullable(), + Text::make('Graph 2 link (default)', 'matters_graph2_link')->nullable(), + Trix::make('Graph 2 caption (default)', 'matters_graph2_caption')->nullable(), + Text::make('Graph 3 image (default)', 'matters_graph3_image')->nullable(), + Text::make('Graph 3 link (default)', 'matters_graph3_link')->nullable(), + Trix::make('Graph 3 caption (default)', 'matters_graph3_caption')->nullable(), + Trix::make('Paragraph 1 (default)', 'matters_paragraph_1')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + Trix::make('Paragraph 2 (default)', 'matters_paragraph_2')->nullable()->help('Use the toolbar for bold, italic, links, lists.'), + ]; + foreach ($locales as $locale) { + if ($locale === 'en') { + continue; + } + $mattersFields[] = $this->localeField('Matters title (' . strtoupper($locale) . ')', $locale, 'matters_title', false); + $mattersFields[] = $this->localeField('Matters paragraph 1 (' . strtoupper($locale) . ')', $locale, 'matters_paragraph_1', true, true); + $mattersFields[] = $this->localeField('Matters paragraph 2 (' . strtoupper($locale) . ')', $locale, 'matters_paragraph_2', true, true); } + $faqFields = [ + Boolean::make('Use dynamic content for this section', 'faq_dynamic'), + Text::make('FAQ section title (default)', 'faq_title')->nullable(), + ]; + foreach ($locales as $locale) { + if ($locale === 'en') { + continue; + } + $faqFields[] = $this->localeField('FAQ title (' . strtoupper($locale) . ')', $locale, 'faq_title', false); + } + $faqFields[] = HasMany::make('FAQ items', 'faqItems', GirlsInDigitalFaqItem::class) + ->help('Add, edit, or reorder FAQ items. Each item has a question and answer (with formatting). Use the Translations panel on each item for other languages.'); + return [ ID::make()->onlyOnForms(), - new Panel('Section toggles (use dynamic content per section)', [ - Boolean::make('Hero dynamic', 'hero_dynamic')->help('Use DB content for hero (intro, video, image).'), - Boolean::make('About dynamic', 'about_dynamic')->help('Use DB content for about section.'), - Boolean::make('Resources dynamic', 'resources_dynamic')->help('Use DB content for resources section.'), - Boolean::make('Why matters dynamic', 'matters_dynamic')->help('Use DB content for "Why Girls in Digital Matters" section.'), - Boolean::make('FAQ dynamic', 'faq_dynamic')->help('Use DB content for FAQ (title + items).'), - ]), - - new Panel('Hero', [ - Textarea::make('Hero intro', 'hero_intro')->nullable(), - Text::make('Hero video URL', 'hero_video_url')->nullable()->help('YouTube embed URL.'), - Text::make('Hero image', 'hero_image')->nullable()->help('Path or URL for hero image.'), - ]), - - 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.'), - Text::make('About image', 'about_image')->nullable(), - ]), - - 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('Young person / parent image', 'resource_young_image')->nullable(), - Text::make('Educator title', 'resource_educator_title')->nullable(), - Textarea::make('Educator description', 'resource_educator_description')->nullable(), - Text::make('Educator image', 'resource_educator_image')->nullable(), - ]), - - new Panel('Why Girls in Digital Matters', [ - 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(), - Textarea::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(), - Textarea::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(), - Textarea::make('Graph 3 caption', 'matters_graph3_caption')->nullable(), - Textarea::make('Paragraph 1', 'matters_paragraph_1')->nullable(), - Textarea::make('Paragraph 2', 'matters_paragraph_2')->nullable(), - ]), - - new Panel('FAQ', [ - Text::make('FAQ section title', 'faq_title')->nullable(), - Code::make('FAQ items', 'faq_items') - ->json() - ->nullable() - ->help('Array of {"question":"...","answer":"..."}. HTML allowed in answer.'), - ]), - - ...$buttonPanels, - - new Panel('Per-locale overrides (optional)', [ - \Laravel\Nova\Fields\Heading::make('Expand a locale to override text for that language.'), - ...$localePanels, - ]), + Panel::make('Section toggles', [ + \Laravel\Nova\Fields\Heading::make('Turn on "Use dynamic content" in each section below to show DB content on the front.'), + ])->collapsable(), + + Panel::make('Hero', $heroFields)->collapsable()->collapsedByDefault(), + + Panel::make('About', $aboutFields)->collapsable()->collapsedByDefault(), + + Panel::make('Resources', $resourcesFields)->collapsable()->collapsedByDefault(), + + Panel::make('Why Girls in Digital Matters', $mattersFields)->collapsable()->collapsedByDefault(), + + Panel::make('FAQ', $faqFields)->collapsable()->collapsedByDefault(), ]; } @@ -211,26 +287,37 @@ private function fillButtonField(\App\GirlsInDigitalPage $model, string $key, st public static function afterSave(NovaRequest $request, $model): void { - $updates = $model->_button_updates ?? null; - if (! is_array($updates) || empty($updates)) { - return; - } - $positionMap = array_flip(array_keys(self::buttonKeys())); - foreach ($updates as $key => $fields) { - $existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first(); - $payload = [ - 'label' => $fields['label'] ?? $existing?->label ?? '', - 'url' => $fields['url'] ?? $existing?->url ?? '#', - 'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false), - 'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true), - 'position' => $positionMap[$key] ?? $existing?->position ?? 0, - ]; - GirlsInDigitalButton::updateOrCreate( - ['page_id' => $model->id, 'key' => $key], - $payload - ); - } - unset($model->_button_updates); + try { + if (! $model->id) { + return; + } + if (! Schema::hasTable('girls_in_digital_buttons')) { + return; + } + $updates = $model->_button_updates ?? null; + if (! is_array($updates) || empty($updates)) { + return; + } + $allKeys = self::allButtonKeys(); + $positionMap = array_flip($allKeys); + foreach ($updates as $key => $fields) { + $existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first(); + $payload = [ + 'label' => array_key_exists('label', $fields) ? (string) $fields['label'] : ($existing?->label ?? ''), + 'url' => array_key_exists('url', $fields) ? (string) $fields['url'] : ($existing?->url ?? '#'), + 'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false), + 'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true), + 'position' => $positionMap[$key] ?? $existing?->position ?? 0, + ]; + GirlsInDigitalButton::updateOrCreate( + ['page_id' => $model->id, 'key' => $key], + $payload + ); + } + unset($model->_button_updates); + } catch (\Throwable $e) { + report($e); + } } public static function afterCreate(NovaRequest $request, $model): void diff --git a/database/migrations/2026_02_12_100000_create_girls_in_digital_faq_items_table.php b/database/migrations/2026_02_12_100000_create_girls_in_digital_faq_items_table.php new file mode 100644 index 000000000..cd92ce197 --- /dev/null +++ b/database/migrations/2026_02_12_100000_create_girls_in_digital_faq_items_table.php @@ -0,0 +1,58 @@ +id(); + $table->unsignedBigInteger('page_id')->default(1); + $table->unsignedInteger('position')->default(0); + $table->text('question')->nullable(); + $table->text('answer')->nullable(); + $table->json('locale_overrides')->nullable(); + $table->timestamps(); + }); + } + + $page = 'girls_in_digital_page'; + if (Schema::hasColumn($page, 'faq_items')) { + $row = DB::table($page)->where('id', 1)->first(); + if ($row && $row->faq_items) { + $items = json_decode($row->faq_items, true); + if (is_array($items)) { + foreach ($items as $i => $item) { + DB::table('girls_in_digital_faq_items')->insert([ + 'page_id' => 1, + 'position' => $i, + 'question' => $item['question'] ?? null, + 'answer' => $item['answer'] ?? null, + 'locale_overrides' => null, + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + } + } + Schema::table($page, function (Blueprint $table) use ($page) { + $table->dropColumn('faq_items'); + }); + } + } + + public function down(): void + { + Schema::dropIfExists('girls_in_digital_faq_items'); + if (! Schema::hasColumn('girls_in_digital_page', 'faq_items')) { + Schema::table('girls_in_digital_page', function (Blueprint $table) { + $table->json('faq_items')->nullable()->after('faq_title'); + }); + } + } +}; diff --git a/resources/views/static/girls-in-digital-week.blade.php b/resources/views/static/girls-in-digital-week.blade.php index 5bdf2d161..96fc22b18 100644 --- a/resources/views/static/girls-in-digital-week.blade.php +++ b/resources/views/static/girls-in-digital-week.blade.php @@ -85,7 +85,7 @@ class="animation-element move-background duration-[1.5s] absolute top-0 left-0 w {{ $content('about_girls_title') ?: 'About Girls in Digital' }}
- {{ $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_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.' !!} @@ -202,7 +202,7 @@ class="animation-element move-background duration-[1.5s] absolute z-0 -bottom-28 {{ $content('resource_educator_title') ?: 'Are you an educator?' }}
- {{ $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') ?: '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.' !!}