Skip to content

Commit 9686d3a

Browse files
authored
Merge pull request #3641 from codeeu/learn-tech-import
Always show Discover Digital Key one-pagers note per locale.
2 parents 3a8f593 + 8ba2d68 commit 9686d3a

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

app/Nova/TrainingResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function fields(Request $request): array
7070
)
7171
->nullable()
7272
->hideFromIndex()
73-
->help('Leave empty to keep the default English PDF links. Use the toolbar to add links (select text → link), lists, and headings. Include [[key_one_pagers_locale_note]] if you want the translated intro sentence.')
73+
->help('Leave empty to keep the default English PDF links. Use the toolbar to add links (select text → link), lists, and headings. For Discover Digital, the Key one-pagers intro sentence is added automatically in the visitor’s language.')
7474
->resolveUsing(function () use ($locale) {
7575
$overrides = $this->resource->locale_overrides ?? [];
7676

app/TrainingResource.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,44 @@ public function hasPdfLinksOverrideForLocale(?string $locale = null): bool
216216

217217
return is_array($replacements) && $replacements !== [];
218218
}
219+
220+
/**
221+
* PDF links HTML with the locale-aware Key one-pagers note applied.
222+
*/
223+
public function renderedPdfLinksSectionForLocale(?string $locale = null): string
224+
{
225+
$section = $this->pdfLinksSectionForLocale($locale);
226+
if ($section === '') {
227+
return '';
228+
}
229+
230+
$noteHtml = '<span class="block mb-4">'.e(__('training.discover_digital_key_one_pagers_note')).'</span>';
231+
232+
if (str_contains($section, '[[key_one_pagers_locale_note]]')) {
233+
return str_replace('[[key_one_pagers_locale_note]]', $noteHtml, $section);
234+
}
235+
236+
// Discover Digital: inject the note even when locale overrides omit the placeholder.
237+
if ($this->slug !== 'discover-digital-programme') {
238+
return $section;
239+
}
240+
241+
$headingPatterns = [
242+
'/(<h2[^>]*\bid=(["\'])key-one-pagers\2[^>]*>.*?<\/h2>)/is',
243+
'/(<h2[^>]*>\s*Key one-pagers\s*<\/h2>)/is',
244+
'/((?:<div[^>]*>\s*)?<strong>\s*Key one-pagers\s*<\/strong>(?:\s*<\/div>)?)/is',
245+
];
246+
247+
foreach ($headingPatterns as $pattern) {
248+
if (preg_match($pattern, $section) === 1) {
249+
return preg_replace($pattern, '$1'.$noteHtml, $section, 1) ?? $section;
250+
}
251+
}
252+
253+
if (! str_contains(mb_strtolower($section), 'key one-pagers')) {
254+
return '<h2 id="key-one-pagers">Key one-pagers</h2>'.$noteHtml.$section;
255+
}
256+
257+
return $noteHtml.$section;
258+
}
219259
}

resources/views/training/show.blade.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,7 @@ class="mb-12 w-full h-full max-h-[630px] object-contain"
132132

133133
@if(!empty($trainingResource->pdf_links_section) || $trainingResource->hasPdfLinksOverrideForLocale())
134134
@php
135-
$pdfLinksSection = $trainingResource->pdfLinksSectionForLocale();
136-
if (str_contains($pdfLinksSection, '[[key_one_pagers_locale_note]]')) {
137-
$pdfLinksSection = str_replace(
138-
'[[key_one_pagers_locale_note]]',
139-
'<span class="block mb-4">'.e(__('training.discover_digital_key_one_pagers_note')).'</span>',
140-
$pdfLinksSection
141-
);
142-
}
135+
$pdfLinksSection = $trainingResource->renderedPdfLinksSectionForLocale();
143136
@endphp
144137
@if($pdfLinksSection !== '')
145138
<div class="{{ $pdfClass }}">

0 commit comments

Comments
 (0)