Skip to content

Commit bfef588

Browse files
authored
Merge pull request #3534 from codeeu/dev
Dev
2 parents c865581 + 7b9ac26 commit bfef588

6 files changed

Lines changed: 108 additions & 5 deletions

File tree

app/Nova/TrainingResource.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,24 +157,26 @@ public function fields(Request $request): array
157157

158158
Select::make('Roadmap embed format', 'roadmap_embed_kind')
159159
->options([
160-
'pdf' => 'PDF (recommended — keeps clickable links from the file)',
160+
'pdf' => 'PDF (inline viewer, links inside the file)',
161+
'image' => 'Image (PNG/JPG thumbnail linking to URL you set)',
161162
'svg' => 'SVG (static graphic; exports usually do not preserve PDF links)',
162163
'none' => 'None (remove placeholder output)',
163164
])
164165
->default('pdf')
165-
->help('Put [[embed_roadmap_pdf]] or [[embed_roadmap]] in Content where the roadmap should appear. Use PDF when the roadmap must open real URLs from the document.'),
166+
->help('Put [[embed_roadmap_pdf]] or [[embed_roadmap]] in Content where the roadmap should appear.'),
166167

167168
Text::make('Roadmap PDF embed URL', 'roadmap_pdf_embed_url')
168169
->nullable()
169170
->rules('nullable', 'url')
170171
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
171-
if (($formData->roadmap_embed_kind ?? 'pdf') === 'pdf') {
172+
$kind = $formData->roadmap_embed_kind ?? 'pdf';
173+
if ($kind === 'pdf' || $kind === 'image') {
172174
$field->show();
173175
} else {
174176
$field->hide();
175177
}
176178
})
177-
->help('HTTPS URL to the PDF. Shown in an iframe with the browser’s built-in PDF viewer so links inside the file stay active.'),
179+
->help('HTTPS URL to the roadmap PDF. For PDF format this is embedded in-page. For Image format use it too (or Roadmap image link URL) as the PDF click target.'),
178180

179181
Textarea::make('Roadmap SVG', 'roadmap_svg')
180182
->nullable()
@@ -188,6 +190,30 @@ public function fields(Request $request): array
188190
})
189191
->help('Optional: paste full <svg>...</svg> only for a non-interactive graphic. For clickable resources, prefer PDF above.'),
190192

193+
Text::make('Roadmap image URL', 'roadmap_image_url')
194+
->nullable()
195+
->rules('nullable', 'url')
196+
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
197+
if (($formData->roadmap_embed_kind ?? 'pdf') === 'image') {
198+
$field->show();
199+
} else {
200+
$field->hide();
201+
}
202+
})
203+
->help('Full URL of the roadmap graphic (e.g. PNG on S3). The whole image is clickable.'),
204+
205+
Text::make('Roadmap image link URL', 'roadmap_image_link_url')
206+
->nullable()
207+
->rules('nullable', 'url')
208+
->dependsOn(['roadmap_embed_kind'], function (Text $field, NovaRequest $request, FormData $formData) {
209+
if (($formData->roadmap_embed_kind ?? 'pdf') === 'image') {
210+
$field->show();
211+
} else {
212+
$field->hide();
213+
}
214+
})
215+
->help('Where clicks go (e.g. full PDF). If empty, falls back to Roadmap PDF embed URL.'),
216+
191217
Text::make('Button text', 'button_text')->nullable(),
192218

193219
Text::make('Button URL', 'button_url')

app/TrainingResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class TrainingResource extends Model
3737
'roadmap_pdf_embed_url',
3838
'roadmap_embed_kind',
3939
'roadmap_svg',
40+
'roadmap_image_url',
41+
'roadmap_image_link_url',
4042
'button_text',
4143
'button_url',
4244
'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_image_url', 2048)->nullable()->after('roadmap_svg');
13+
$table->string('roadmap_image_link_url', 2048)->nullable()->after('roadmap_image_url');
14+
});
15+
}
16+
17+
public function down(): void
18+
{
19+
Schema::table('training_resources', function (Blueprint $table) {
20+
$table->dropColumn(['roadmap_image_url', 'roadmap_image_link_url']);
21+
});
22+
}
23+
};

database/seeders/TrainingResourceDiscoverDigitalProgrammeSeeder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public function run(): void
9393
'roadmap_pdf_embed_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.pdf',
9494
'roadmap_embed_kind' => 'pdf',
9595
'roadmap_svg' => null,
96+
'roadmap_image_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.png',
97+
'roadmap_image_link_url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/+discover-digital-toolkit/DDP_toolkit_roadmap.pdf',
9698
'third_button_text' => 'Register an activity',
9799
'third_button_url' => 'https://codeweek.eu/add?skip=1',
98100
'meta_title' => 'Discover Digital Programme - Toolkit',
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@props([
2+
'imageUrl',
3+
'linkUrl',
4+
'altText' => null,
5+
])
6+
@php
7+
$alt = $altText !== null && trim((string) $altText) !== '' ? trim((string) $altText) : __('Roadmap overview');
8+
$external = \Illuminate\Support\Str::startsWith($linkUrl, ['http://', 'https://', '//']);
9+
@endphp
10+
<div class="w-full max-w-full my-6 rounded-xl overflow-hidden border border-slate-200 bg-slate-100 shadow-sm">
11+
<a
12+
href="{{ $linkUrl }}"
13+
@if($external)
14+
target="_blank"
15+
rel="noopener noreferrer"
16+
@endif
17+
class="block focus:outline-none focus-visible:ring-2 focus-visible:ring-dark-blue focus-visible:ring-offset-2 rounded-xl"
18+
>
19+
<img
20+
src="{{ $imageUrl }}"
21+
alt="{{ $alt }}"
22+
class="block w-full h-auto max-w-full"
23+
loading="lazy"
24+
decoding="async"
25+
>
26+
</a>
27+
</div>
28+
<p class="text-sm mt-2 mb-0 text-[#333E48]">
29+
<a
30+
href="{{ $linkUrl }}"
31+
@if($external)
32+
target="_blank"
33+
rel="noopener noreferrer"
34+
@endif
35+
class="text-dark-blue underline font-medium"
36+
>
37+
{{ __('Open linked resource') }}
38+
</a>
39+
{{ __('same destination as clicking the image above.') }}
40+
</p>

resources/views/training/show.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
$renderedContent = $trainingResource->content ?? '';
2828
$roadmapEmbedUrl = trim((string) ($trainingResource->roadmap_pdf_embed_url ?? ''));
2929
$roadmapEmbedKind = strtolower(trim((string) ($trainingResource->roadmap_embed_kind ?? 'pdf')));
30-
if (! in_array($roadmapEmbedKind, ['pdf', 'svg', 'none'], true)) {
30+
if (! in_array($roadmapEmbedKind, ['pdf', 'svg', 'image', 'none'], true)) {
3131
$roadmapEmbedKind = 'pdf';
3232
}
3333
$roadmapSvg = trim((string) ($trainingResource->roadmap_svg ?? ''));
34+
$roadmapImageUrl = trim((string) ($trainingResource->roadmap_image_url ?? ''));
35+
$roadmapImageLinkUrl = trim((string) ($trainingResource->roadmap_image_link_url ?? ''));
3436
3537
$roadmapPlaceholders = ['[[embed_roadmap_pdf]]', '[[embed_roadmap]]'];
3638
$hasRoadmapPlaceholder = str_contains($renderedContent, '[[embed_roadmap_pdf]]')
@@ -42,6 +44,14 @@
4244
$roadmapEmbedHtml = view('training.partials.roadmap-pdf-embed', ['url' => $roadmapEmbedUrl])->render();
4345
} elseif ($roadmapEmbedKind === 'svg' && $roadmapSvg !== '') {
4446
$roadmapEmbedHtml = view('training.partials.roadmap-svg-embed', ['svg' => $roadmapSvg])->render();
47+
} elseif ($roadmapEmbedKind === 'image' && $roadmapImageUrl !== '') {
48+
$imageLinkHref = $roadmapImageLinkUrl !== '' ? $roadmapImageLinkUrl : $roadmapEmbedUrl;
49+
if ($imageLinkHref !== '') {
50+
$roadmapEmbedHtml = view('training.partials.roadmap-image-embed', [
51+
'imageUrl' => $roadmapImageUrl,
52+
'linkUrl' => $imageLinkHref,
53+
])->render();
54+
}
4555
}
4656
4757
foreach ($roadmapPlaceholders as $token) {

0 commit comments

Comments
 (0)