Skip to content

Commit 1b528e1

Browse files
committed
feat(training): choose roadmap embed as PDF or inline SVG
- Add roadmap_embed_kind (pdf|svg|none) and roadmap_svg (mediumText) - Support [[embed_roadmap]] alongside [[embed_roadmap_pdf]] - Nova shows PDF URL or SVG textarea based on format Made-with: Cursor
1 parent fb78f2c commit 1b528e1

6 files changed

Lines changed: 87 additions & 9 deletions

File tree

app/Nova/TrainingResource.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
use Illuminate\Http\Request;
77
use Illuminate\Support\Facades\URL;
88
use Laravel\Nova\Fields\Boolean;
9+
use Laravel\Nova\Fields\FormData;
910
use Laravel\Nova\Fields\ID;
1011
use Laravel\Nova\Fields\Number;
12+
use Laravel\Nova\Fields\Select;
1113
use Laravel\Nova\Fields\Text;
1214
use Laravel\Nova\Fields\Textarea;
1315
use Laravel\Nova\Fields\Trix;
@@ -153,10 +155,38 @@ public function fields(Request $request): array
153155
->nullable()
154156
->help('Optional scroll offset in pixels for in-page anchor links (useful with sticky headers).'),
155157

158+
Select::make('Roadmap embed format', 'roadmap_embed_kind')
159+
->options([
160+
'pdf' => 'PDF (inline viewer)',
161+
'svg' => 'SVG (paste markup below)',
162+
'none' => 'None (remove placeholder output)',
163+
])
164+
->default('pdf')
165+
->help('Use [[embed_roadmap_pdf]] or [[embed_roadmap]] in Content where the roadmap should appear.'),
166+
156167
Text::make('Roadmap PDF embed URL', 'roadmap_pdf_embed_url')
157168
->nullable()
158169
->rules('nullable', 'url')
159-
->help('Optional HTTPS URL to a PDF shown inline in the Roadmap section. Put the literal text [[embed_roadmap_pdf]] in Content where the embed should appear (avoids Nova stripping iframes).'),
170+
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
171+
if (($formData->roadmap_embed_kind ?? 'pdf') === 'pdf') {
172+
$field->show();
173+
} else {
174+
$field->hide();
175+
}
176+
})
177+
->help('HTTPS URL to the roadmap PDF. Used when format is PDF.'),
178+
179+
Textarea::make('Roadmap SVG', 'roadmap_svg')
180+
->nullable()
181+
->rows(10)
182+
->dependsOn(['roadmap_embed_kind'], function (Textarea $field, NovaRequest $request, FormData $formData) {
183+
if (($formData->roadmap_embed_kind ?? 'pdf') === 'svg') {
184+
$field->show();
185+
} else {
186+
$field->hide();
187+
}
188+
})
189+
->help('Full <svg>...</svg> markup from your design tool. Used when format is SVG.'),
160190

161191
Text::make('Button text', 'button_text')->nullable(),
162192

app/TrainingResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class TrainingResource extends Model
3535
'about_box_section',
3636
'anchor_offset',
3737
'roadmap_pdf_embed_url',
38+
'roadmap_embed_kind',
39+
'roadmap_svg',
3840
'button_text',
3941
'button_url',
4042
'secondary_button_text',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
{
9+
public function up(): void
10+
{
11+
Schema::table('training_resources', function (Blueprint $table) {
12+
$table->string('roadmap_embed_kind', 16)->default('pdf')->after('roadmap_pdf_embed_url');
13+
$table->mediumText('roadmap_svg')->nullable()->after('roadmap_embed_kind');
14+
});
15+
}
16+
17+
public function down(): void
18+
{
19+
Schema::table('training_resources', function (Blueprint $table) {
20+
$table->dropColumn(['roadmap_embed_kind', 'roadmap_svg']);
21+
});
22+
}
23+
};

database/seeders/TrainingResourceDiscoverDigitalProgrammeSeeder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function run(): void
9191
HTML,
9292
'anchor_offset' => 120,
9393
'roadmap_pdf_embed_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.pdf',
94+
'roadmap_embed_kind' => 'pdf',
95+
'roadmap_svg' => null,
9496
'third_button_text' => 'Register an activity',
9597
'third_button_url' => 'https://codeweek.eu/add?skip=1',
9698
'meta_title' => 'Discover Digital Programme - Toolkit',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@props([
2+
'svg',
3+
])
4+
<div class="w-full max-w-full my-6 rounded-xl overflow-hidden border border-slate-200 bg-slate-50 shadow-sm [&_svg]:max-w-full [&_svg]:h-auto [&_svg]:block">
5+
{!! $svg !!}
6+
</div>

resources/views/training/show.blade.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,29 @@
2626
2727
$renderedContent = $trainingResource->content ?? '';
2828
$roadmapEmbedUrl = trim((string) ($trainingResource->roadmap_pdf_embed_url ?? ''));
29-
if ($roadmapEmbedUrl !== '' && str_contains($renderedContent, '[[embed_roadmap_pdf]]')) {
30-
$renderedContent = str_replace(
31-
'[[embed_roadmap_pdf]]',
32-
view('training.partials.roadmap-pdf-embed', ['url' => $roadmapEmbedUrl])->render(),
33-
$renderedContent
34-
);
35-
} elseif (str_contains($renderedContent, '[[embed_roadmap_pdf]]')) {
36-
$renderedContent = str_replace('[[embed_roadmap_pdf]]', '', $renderedContent);
29+
$roadmapEmbedKind = strtolower(trim((string) ($trainingResource->roadmap_embed_kind ?? 'pdf')));
30+
if (! in_array($roadmapEmbedKind, ['pdf', 'svg', 'none'], true)) {
31+
$roadmapEmbedKind = 'pdf';
32+
}
33+
$roadmapSvg = trim((string) ($trainingResource->roadmap_svg ?? ''));
34+
35+
$roadmapPlaceholders = ['[[embed_roadmap_pdf]]', '[[embed_roadmap]]'];
36+
$hasRoadmapPlaceholder = str_contains($renderedContent, '[[embed_roadmap_pdf]]')
37+
|| str_contains($renderedContent, '[[embed_roadmap]]');
38+
39+
if ($hasRoadmapPlaceholder) {
40+
$roadmapEmbedHtml = '';
41+
if ($roadmapEmbedKind === 'pdf' && $roadmapEmbedUrl !== '') {
42+
$roadmapEmbedHtml = view('training.partials.roadmap-pdf-embed', ['url' => $roadmapEmbedUrl])->render();
43+
} elseif ($roadmapEmbedKind === 'svg' && $roadmapSvg !== '') {
44+
$roadmapEmbedHtml = view('training.partials.roadmap-svg-embed', ['svg' => $roadmapSvg])->render();
45+
}
46+
47+
foreach ($roadmapPlaceholders as $token) {
48+
if (str_contains($renderedContent, $token)) {
49+
$renderedContent = str_replace($token, $roadmapEmbedHtml, $renderedContent);
50+
}
51+
}
3752
}
3853
@endphp
3954

0 commit comments

Comments
 (0)