Skip to content

Commit 08cf03b

Browse files
authored
Merge pull request #3415 from codeeu/dev
Dev
2 parents eef0842 + 033a1b3 commit 08cf03b

6 files changed

Lines changed: 63 additions & 148 deletions

File tree

app/HackathonsPage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class HackathonsPage extends Model
2121
'details_paragraph_3',
2222
'details_paragraph_4',
2323
'video_url',
24+
'extra_button_text',
25+
'extra_button_link',
2426
'recap_button_text',
2527
'recap_button_link',
2628
'toolkit_button_text',

app/Nova/DreamJobsPage.php

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\Request;
66
use Laravel\Nova\Fields\Boolean;
7+
use Laravel\Nova\Fields\Code;
78
use Laravel\Nova\Fields\HasMany;
89
use Laravel\Nova\Fields\ID;
910
use Laravel\Nova\Fields\Text;
@@ -39,70 +40,8 @@ public static function indexQuery(NovaRequest $request, $query)
3940
return $query->where('id', 1);
4041
}
4142

42-
private static function localesSorted(): array
43-
{
44-
$locales = config('app.locales', ['en']);
45-
if (is_string($locales)) {
46-
$locales = array_map('trim', explode(',', $locales));
47-
}
48-
$locales = array_values(array_filter($locales));
49-
if (empty($locales)) {
50-
$locales = ['en'];
51-
}
52-
sort($locales);
53-
54-
return $locales;
55-
}
56-
5743
public function fields(Request $request): array
5844
{
59-
$translationKeys = [
60-
'hero_intro' => 'Hero intro',
61-
'hero_cta_text' => 'Hero button text',
62-
'about_title' => 'About title',
63-
'about_description' => 'About description',
64-
'role_models_title' => 'Role models section title',
65-
'resources_title' => 'Resources section title',
66-
];
67-
68-
$translationFields = [];
69-
foreach (self::localesSorted() as $locale) {
70-
if ($locale === 'en') {
71-
continue;
72-
}
73-
foreach ($translationKeys as $key => $label) {
74-
$isLongText = in_array($key, ['hero_intro', 'about_description'], true);
75-
$fieldName = 'locale_' . $locale . '_' . $key;
76-
if ($isLongText) {
77-
$translationFields[] = Textarea::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
78-
->nullable()
79-
->resolveUsing(function () use ($locale, $key) {
80-
$overrides = $this->resource->locale_overrides ?? [];
81-
82-
return $overrides[$locale][$key] ?? '';
83-
})
84-
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
85-
$overrides = $model->locale_overrides ?? [];
86-
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
87-
$model->locale_overrides = $overrides;
88-
});
89-
} else {
90-
$translationFields[] = Text::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
91-
->nullable()
92-
->resolveUsing(function () use ($locale, $key) {
93-
$overrides = $this->resource->locale_overrides ?? [];
94-
95-
return $overrides[$locale][$key] ?? '';
96-
})
97-
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
98-
$overrides = $model->locale_overrides ?? [];
99-
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
100-
$model->locale_overrides = $overrides;
101-
});
102-
}
103-
}
104-
}
105-
10645
$resourcesPanelFields = [
10746
Boolean::make('Use dynamic content for this section', 'resources_dynamic'),
10847
Text::make('Resources section title', 'resources_title')->nullable(),
@@ -136,12 +75,13 @@ public function fields(Request $request): array
13675
Panel::make('Resources section (global for all role model pages)', $resourcesPanelFields)
13776
->collapsable()
13877
->collapsedByDefault(),
78+
Panel::make('Translations (JSON)', [
79+
Code::make('Locale overrides', 'locale_overrides')
80+
->json()
81+
->help('Optional per-locale overrides. Example: {"fr":{"hero_intro":"..."}}'),
82+
])->collapsable()->collapsedByDefault(),
13983
];
14084

141-
if (!empty($translationFields)) {
142-
$fields[] = new Panel('Translations', $translationFields);
143-
}
144-
14585
return $fields;
14686
}
14787
}

app/Nova/HackathonsPage.php

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\Request;
66
use Laravel\Nova\Fields\Boolean;
7+
use Laravel\Nova\Fields\Code;
78
use Laravel\Nova\Fields\ID;
89
use Laravel\Nova\Fields\Text;
910
use Laravel\Nova\Fields\Trix;
@@ -38,86 +39,8 @@ public static function indexQuery(NovaRequest $request, $query)
3839
return $query->where('id', 1);
3940
}
4041

41-
private static function localesSorted(): array
42-
{
43-
$locales = config('app.locales', ['en']);
44-
if (is_string($locales)) {
45-
$locales = array_map('trim', explode(',', $locales));
46-
}
47-
$locales = array_values(array_filter($locales));
48-
if (empty($locales)) {
49-
$locales = ['en'];
50-
}
51-
sort($locales);
52-
53-
return $locales;
54-
}
55-
5642
public function fields(Request $request): array
5743
{
58-
$translationKeys = [
59-
'hero_title' => 'Hero title',
60-
'hero_subtitle' => 'Hero subtitle',
61-
'intro_title' => 'Intro title',
62-
'intro_paragraph_1' => 'Intro paragraph 1',
63-
'intro_paragraph_2' => 'Intro paragraph 2',
64-
'details_title' => 'Details title',
65-
'details_paragraph_1' => 'Details paragraph 1',
66-
'details_paragraph_2' => 'Details paragraph 2',
67-
'details_paragraph_3' => 'Details paragraph 3',
68-
'details_paragraph_4' => 'Details paragraph 4',
69-
'recap_button_text' => 'Recap button text',
70-
'toolkit_button_text' => 'Toolkit button text',
71-
];
72-
73-
$longTextKeys = [
74-
'hero_subtitle',
75-
'intro_paragraph_1',
76-
'intro_paragraph_2',
77-
'details_paragraph_1',
78-
'details_paragraph_2',
79-
'details_paragraph_3',
80-
'details_paragraph_4',
81-
];
82-
83-
$translationFields = [];
84-
foreach (self::localesSorted() as $locale) {
85-
if ($locale === 'en') {
86-
continue;
87-
}
88-
89-
foreach ($translationKeys as $key => $label) {
90-
$fieldName = 'locale_' . $locale . '_' . $key;
91-
if (in_array($key, $longTextKeys, true)) {
92-
$translationFields[] = Trix::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
93-
->nullable()
94-
->resolveUsing(function () use ($locale, $key) {
95-
$overrides = $this->resource->locale_overrides ?? [];
96-
97-
return $overrides[$locale][$key] ?? '';
98-
})
99-
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
100-
$overrides = $model->locale_overrides ?? [];
101-
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
102-
$model->locale_overrides = $overrides;
103-
});
104-
} else {
105-
$translationFields[] = Text::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
106-
->nullable()
107-
->resolveUsing(function () use ($locale, $key) {
108-
$overrides = $this->resource->locale_overrides ?? [];
109-
110-
return $overrides[$locale][$key] ?? '';
111-
})
112-
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
113-
$overrides = $model->locale_overrides ?? [];
114-
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
115-
$model->locale_overrides = $overrides;
116-
});
117-
}
118-
}
119-
}
120-
12144
$fields = [
12245
ID::make()->onlyOnForms(),
12346
Boolean::make('Use dynamic content', 'dynamic_content')
@@ -141,17 +64,20 @@ public function fields(Request $request): array
14164
Trix::make('Details paragraph 3', 'details_paragraph_3')->nullable(),
14265
Trix::make('Details paragraph 4', 'details_paragraph_4')->nullable(),
14366
Text::make('Video URL (embed)', 'video_url')->nullable(),
67+
Text::make('Extra button text (optional)', 'extra_button_text')->nullable(),
68+
Text::make('Extra button link (optional)', 'extra_button_link')->nullable(),
14469
Text::make('Recap button text', 'recap_button_text')->nullable(),
14570
Text::make('Recap button link', 'recap_button_link')->nullable(),
14671
Text::make('Toolkit button text', 'toolkit_button_text')->nullable(),
14772
Text::make('Toolkit button link', 'toolkit_button_link')->nullable(),
14873
])->collapsable()->collapsedByDefault(),
74+
Panel::make('Translations (JSON)', [
75+
Code::make('Locale overrides', 'locale_overrides')
76+
->json()
77+
->help('Optional per-locale overrides. Example: {"fr":{"hero_title":"Hackathons"}}'),
78+
])->collapsable()->collapsedByDefault(),
14979
];
15080

151-
if (!empty($translationFields)) {
152-
$fields[] = new Panel('Translations', $translationFields);
153-
}
154-
15581
return $fields;
15682
}
15783
}

database/migrations/2026_02_16_140000_create_hackathons_page_table.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function up(): void
2323
$table->text('details_paragraph_3')->nullable();
2424
$table->text('details_paragraph_4')->nullable();
2525
$table->string('video_url')->nullable();
26+
$table->string('extra_button_text')->nullable();
27+
$table->string('extra_button_link')->nullable();
2628
$table->string('recap_button_text')->nullable();
2729
$table->string('recap_button_link')->nullable();
2830
$table->string('toolkit_button_text')->nullable();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
if (Schema::hasTable('hackathons_page') && !Schema::hasColumn('hackathons_page', 'extra_button_text')) {
11+
Schema::table('hackathons_page', function (Blueprint $table) {
12+
$table->string('extra_button_text')->nullable()->after('video_url');
13+
});
14+
}
15+
16+
if (Schema::hasTable('hackathons_page') && !Schema::hasColumn('hackathons_page', 'extra_button_link')) {
17+
Schema::table('hackathons_page', function (Blueprint $table) {
18+
$table->string('extra_button_link')->nullable()->after('extra_button_text');
19+
});
20+
}
21+
}
22+
23+
public function down(): void
24+
{
25+
if (Schema::hasTable('hackathons_page') && Schema::hasColumn('hackathons_page', 'extra_button_link')) {
26+
Schema::table('hackathons_page', function (Blueprint $table) {
27+
$table->dropColumn('extra_button_link');
28+
});
29+
}
30+
31+
if (Schema::hasTable('hackathons_page') && Schema::hasColumn('hackathons_page', 'extra_button_text')) {
32+
Schema::table('hackathons_page', function (Blueprint $table) {
33+
$table->dropColumn('extra_button_text');
34+
});
35+
}
36+
}
37+
};

resources/views/hackathons/index.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ class="animation-element move-background duration-[1.5s] absolute z-0 lg:-bottom
150150
@endif
151151
</p>
152152
<div class="flex flex-col gap-x-2 gap-y-4 tablet:flex-row lg:flex-col 2xl:flex-row">
153+
@if($dynamic && $page && $page->extra_button_link && $page->contentForLocale('extra_button_text'))
154+
<a
155+
class="inline-block bg-primary hover:bg-hover-orange rounded-full py-4 px-6 md:px-10 font-semibold text-base w-full md:w-auto text-center text-[#20262C] transition-all duration-300"
156+
target="_blank" href="{{ $page->extra_button_link }}"
157+
>
158+
{{ $page->contentForLocale('extra_button_text') }}
159+
</a>
160+
@endif
153161
<a
154162
class="inline-block bg-primary hover:bg-hover-orange rounded-full py-4 px-6 md:px-10 font-semibold text-base w-full md:w-auto text-center text-[#20262C] transition-all duration-300"
155163
target="_blank" href="{{ ($dynamic && $page && $page->recap_button_link) ? $page->recap_button_link : 'https://eventornado.com/event/eu-codeweek-hackathon2024#Finals%20-%20EU%20Code%20Week%20Hackathon%202024' }}"

0 commit comments

Comments
 (0)