Skip to content
Merged
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: 1 addition & 1 deletion app/Nova/TrainingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function fields(Request $request): array
)
->nullable()
->hideFromIndex()
->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.')
->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.')
->resolveUsing(function () use ($locale) {
$overrides = $this->resource->locale_overrides ?? [];

Expand Down
40 changes: 40 additions & 0 deletions app/TrainingResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,44 @@ public function hasPdfLinksOverrideForLocale(?string $locale = null): bool

return is_array($replacements) && $replacements !== [];
}

/**
* PDF links HTML with the locale-aware Key one-pagers note applied.
*/
public function renderedPdfLinksSectionForLocale(?string $locale = null): string
{
$section = $this->pdfLinksSectionForLocale($locale);
if ($section === '') {
return '';
}

$noteHtml = '<span class="block mb-4">'.e(__('training.discover_digital_key_one_pagers_note')).'</span>';

if (str_contains($section, '[[key_one_pagers_locale_note]]')) {
return str_replace('[[key_one_pagers_locale_note]]', $noteHtml, $section);
}

// Discover Digital: inject the note even when locale overrides omit the placeholder.
if ($this->slug !== 'discover-digital-programme') {
return $section;
}

$headingPatterns = [
'/(<h2[^>]*\bid=(["\'])key-one-pagers\2[^>]*>.*?<\/h2>)/is',
'/(<h2[^>]*>\s*Key one-pagers\s*<\/h2>)/is',
'/((?:<div[^>]*>\s*)?<strong>\s*Key one-pagers\s*<\/strong>(?:\s*<\/div>)?)/is',
];

foreach ($headingPatterns as $pattern) {
if (preg_match($pattern, $section) === 1) {
return preg_replace($pattern, '$1'.$noteHtml, $section, 1) ?? $section;
}
}

if (! str_contains(mb_strtolower($section), 'key one-pagers')) {
return '<h2 id="key-one-pagers">Key one-pagers</h2>'.$noteHtml.$section;
}

return $noteHtml.$section;
}
}
9 changes: 1 addition & 8 deletions resources/views/training/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,7 @@ class="mb-12 w-full h-full max-h-[630px] object-contain"

@if(!empty($trainingResource->pdf_links_section) || $trainingResource->hasPdfLinksOverrideForLocale())
@php
$pdfLinksSection = $trainingResource->pdfLinksSectionForLocale();
if (str_contains($pdfLinksSection, '[[key_one_pagers_locale_note]]')) {
$pdfLinksSection = str_replace(
'[[key_one_pagers_locale_note]]',
'<span class="block mb-4">'.e(__('training.discover_digital_key_one_pagers_note')).'</span>',
$pdfLinksSection
);
}
$pdfLinksSection = $trainingResource->renderedPdfLinksSectionForLocale();
@endphp
@if($pdfLinksSection !== '')
<div class="{{ $pdfClass }}">
Expand Down
Loading