From 8ba2d689d88f69024df488128a797c766fa89a16 Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Fri, 24 Jul 2026 11:19:36 +0100 Subject: [PATCH] Always show Discover Digital Key one-pagers note per locale. Romanian PDF overrides often omit the placeholder, so inject the translated intro automatically after the heading (or restore the heading when missing). Co-authored-by: Cursor --- app/Nova/TrainingResource.php | 2 +- app/TrainingResource.php | 40 +++++++++++++++++++++++++ resources/views/training/show.blade.php | 9 +----- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/Nova/TrainingResource.php b/app/Nova/TrainingResource.php index 62809ffb9..0be886d64 100644 --- a/app/Nova/TrainingResource.php +++ b/app/Nova/TrainingResource.php @@ -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 ?? []; diff --git a/app/TrainingResource.php b/app/TrainingResource.php index a4a117a3c..8b8c8dd98 100644 --- a/app/TrainingResource.php +++ b/app/TrainingResource.php @@ -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 = ''.e(__('training.discover_digital_key_one_pagers_note')).''; + + 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 = [ + '/(]*\bid=(["\'])key-one-pagers\2[^>]*>.*?<\/h2>)/is', + '/(]*>\s*Key one-pagers\s*<\/h2>)/is', + '/((?:]*>\s*)?\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 '

Key one-pagers

'.$noteHtml.$section; + } + + return $noteHtml.$section; + } } diff --git a/resources/views/training/show.blade.php b/resources/views/training/show.blade.php index 34a3648a6..4dfbb98d1 100644 --- a/resources/views/training/show.blade.php +++ b/resources/views/training/show.blade.php @@ -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]]', - ''.e(__('training.discover_digital_key_one_pagers_note')).'', - $pdfLinksSection - ); - } + $pdfLinksSection = $trainingResource->renderedPdfLinksSectionForLocale(); @endphp @if($pdfLinksSection !== '')