Skip to content
Merged

Dev #3415

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/HackathonsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class HackathonsPage extends Model
'details_paragraph_3',
'details_paragraph_4',
'video_url',
'extra_button_text',
'extra_button_link',
'recap_button_text',
'recap_button_link',
'toolkit_button_text',
Expand Down
72 changes: 6 additions & 66 deletions app/Nova/DreamJobsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
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;
Expand Down Expand Up @@ -39,70 +40,8 @@ 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;
}

public function fields(Request $request): array
{
$translationKeys = [
'hero_intro' => 'Hero intro',
'hero_cta_text' => 'Hero button text',
'about_title' => 'About title',
'about_description' => 'About description',
'role_models_title' => 'Role models section title',
'resources_title' => 'Resources section title',
];

$translationFields = [];
foreach (self::localesSorted() as $locale) {
if ($locale === 'en') {
continue;
}
foreach ($translationKeys as $key => $label) {
$isLongText = in_array($key, ['hero_intro', 'about_description'], true);
$fieldName = 'locale_' . $locale . '_' . $key;
if ($isLongText) {
$translationFields[] = Textarea::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
->nullable()
->resolveUsing(function () use ($locale, $key) {
$overrides = $this->resource->locale_overrides ?? [];

return $overrides[$locale][$key] ?? '';
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
$overrides = $model->locale_overrides ?? [];
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
$model->locale_overrides = $overrides;
});
} else {
$translationFields[] = Text::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
->nullable()
->resolveUsing(function () use ($locale, $key) {
$overrides = $this->resource->locale_overrides ?? [];

return $overrides[$locale][$key] ?? '';
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
$overrides = $model->locale_overrides ?? [];
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
$model->locale_overrides = $overrides;
});
}
}
}

$resourcesPanelFields = [
Boolean::make('Use dynamic content for this section', 'resources_dynamic'),
Text::make('Resources section title', 'resources_title')->nullable(),
Expand Down Expand Up @@ -136,12 +75,13 @@ public function fields(Request $request): array
Panel::make('Resources section (global for all role model pages)', $resourcesPanelFields)
->collapsable()
->collapsedByDefault(),
Panel::make('Translations (JSON)', [
Code::make('Locale overrides', 'locale_overrides')
->json()
->help('Optional per-locale overrides. Example: {"fr":{"hero_intro":"..."}}'),
])->collapsable()->collapsedByDefault(),
];

if (!empty($translationFields)) {
$fields[] = new Panel('Translations', $translationFields);
}

return $fields;
}
}
90 changes: 8 additions & 82 deletions app/Nova/HackathonsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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\Trix;
Expand Down Expand Up @@ -38,86 +39,8 @@ 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;
}

public function fields(Request $request): array
{
$translationKeys = [
'hero_title' => 'Hero title',
'hero_subtitle' => 'Hero subtitle',
'intro_title' => 'Intro title',
'intro_paragraph_1' => 'Intro paragraph 1',
'intro_paragraph_2' => 'Intro paragraph 2',
'details_title' => 'Details title',
'details_paragraph_1' => 'Details paragraph 1',
'details_paragraph_2' => 'Details paragraph 2',
'details_paragraph_3' => 'Details paragraph 3',
'details_paragraph_4' => 'Details paragraph 4',
'recap_button_text' => 'Recap button text',
'toolkit_button_text' => 'Toolkit button text',
];

$longTextKeys = [
'hero_subtitle',
'intro_paragraph_1',
'intro_paragraph_2',
'details_paragraph_1',
'details_paragraph_2',
'details_paragraph_3',
'details_paragraph_4',
];

$translationFields = [];
foreach (self::localesSorted() as $locale) {
if ($locale === 'en') {
continue;
}

foreach ($translationKeys as $key => $label) {
$fieldName = 'locale_' . $locale . '_' . $key;
if (in_array($key, $longTextKeys, true)) {
$translationFields[] = Trix::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
->nullable()
->resolveUsing(function () use ($locale, $key) {
$overrides = $this->resource->locale_overrides ?? [];

return $overrides[$locale][$key] ?? '';
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
$overrides = $model->locale_overrides ?? [];
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
$model->locale_overrides = $overrides;
});
} else {
$translationFields[] = Text::make($label . ' (' . strtoupper($locale) . ')', $fieldName)
->nullable()
->resolveUsing(function () use ($locale, $key) {
$overrides = $this->resource->locale_overrides ?? [];

return $overrides[$locale][$key] ?? '';
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) use ($locale, $key) {
$overrides = $model->locale_overrides ?? [];
$overrides[$locale][$key] = $request->get($requestAttribute) ?: null;
$model->locale_overrides = $overrides;
});
}
}
}

$fields = [
ID::make()->onlyOnForms(),
Boolean::make('Use dynamic content', 'dynamic_content')
Expand All @@ -141,17 +64,20 @@ public function fields(Request $request): array
Trix::make('Details paragraph 3', 'details_paragraph_3')->nullable(),
Trix::make('Details paragraph 4', 'details_paragraph_4')->nullable(),
Text::make('Video URL (embed)', 'video_url')->nullable(),
Text::make('Extra button text (optional)', 'extra_button_text')->nullable(),
Text::make('Extra button link (optional)', 'extra_button_link')->nullable(),
Text::make('Recap button text', 'recap_button_text')->nullable(),
Text::make('Recap button link', 'recap_button_link')->nullable(),
Text::make('Toolkit button text', 'toolkit_button_text')->nullable(),
Text::make('Toolkit button link', 'toolkit_button_link')->nullable(),
])->collapsable()->collapsedByDefault(),
Panel::make('Translations (JSON)', [
Code::make('Locale overrides', 'locale_overrides')
->json()
->help('Optional per-locale overrides. Example: {"fr":{"hero_title":"Hackathons"}}'),
])->collapsable()->collapsedByDefault(),
];

if (!empty($translationFields)) {
$fields[] = new Panel('Translations', $translationFields);
}

return $fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function up(): void
$table->text('details_paragraph_3')->nullable();
$table->text('details_paragraph_4')->nullable();
$table->string('video_url')->nullable();
$table->string('extra_button_text')->nullable();
$table->string('extra_button_link')->nullable();
$table->string('recap_button_text')->nullable();
$table->string('recap_button_link')->nullable();
$table->string('toolkit_button_text')->nullable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
if (Schema::hasTable('hackathons_page') && !Schema::hasColumn('hackathons_page', 'extra_button_text')) {
Schema::table('hackathons_page', function (Blueprint $table) {
$table->string('extra_button_text')->nullable()->after('video_url');
});
}

if (Schema::hasTable('hackathons_page') && !Schema::hasColumn('hackathons_page', 'extra_button_link')) {
Schema::table('hackathons_page', function (Blueprint $table) {
$table->string('extra_button_link')->nullable()->after('extra_button_text');
});
}
}

public function down(): void
{
if (Schema::hasTable('hackathons_page') && Schema::hasColumn('hackathons_page', 'extra_button_link')) {
Schema::table('hackathons_page', function (Blueprint $table) {
$table->dropColumn('extra_button_link');
});
}

if (Schema::hasTable('hackathons_page') && Schema::hasColumn('hackathons_page', 'extra_button_text')) {
Schema::table('hackathons_page', function (Blueprint $table) {
$table->dropColumn('extra_button_text');
});
}
}
};
8 changes: 8 additions & 0 deletions resources/views/hackathons/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ class="animation-element move-background duration-[1.5s] absolute z-0 lg:-bottom
@endif
</p>
<div class="flex flex-col gap-x-2 gap-y-4 tablet:flex-row lg:flex-col 2xl:flex-row">
@if($dynamic && $page && $page->extra_button_link && $page->contentForLocale('extra_button_text'))
<a
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"
target="_blank" href="{{ $page->extra_button_link }}"
>
{{ $page->contentForLocale('extra_button_text') }}
</a>
@endif
<a
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"
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' }}"
Expand Down
Loading