55namespace Hofff \Contao \ContactProfiles \EventListener ;
66
77use Contao \CoreBundle \InsertTag \InsertTagParser ;
8+ use Contao \CoreBundle \Routing \ResponseContext \HtmlHeadBag \HtmlHeadBag ;
9+ use Contao \CoreBundle \Routing \ResponseContext \ResponseContextAccessor ;
10+ use Contao \CoreBundle \String \HtmlDecoder ;
811use Contao \StringUtil ;
912use Hofff \Contao \ContactProfiles \Event \ProfileDetailPageEvent ;
1013use Hofff \Contao \ContactProfiles \SocialTags \SocialTagsGenerator ;
@@ -18,6 +21,8 @@ final class DetailPageListener
1821 public function __construct (
1922 private readonly InsertTagParser $ insertTagParser ,
2023 private readonly SocialTagsGenerator $ socialTagsGenerator ,
24+ private readonly ResponseContextAccessor $ responseContextAccessor ,
25+ private readonly HtmlDecoder $ htmlDecoder ,
2126 ) {
2227 }
2328
@@ -33,6 +38,14 @@ public function __invoke(ProfileDetailPageEvent $event): void
3338 $ GLOBALS ['objPage ' ]->pageTitle = trim ($ profile ->firstname . ' ' . $ profile ->lastname );
3439 $ GLOBALS ['objPage ' ]->description = $ this ->prepareMetaDescription ((string ) $ profile ->teaser );
3540
41+ $ context = $ this ->responseContextAccessor ->getResponseContext ();
42+ if ($ context && $ context ->has (HtmlHeadBag::class)) {
43+ $ bag = $ context ->get (HtmlHeadBag::class);
44+
45+ $ bag ->setTitle ($ GLOBALS ['objPage ' ]->pageTitle );
46+ $ bag ->setMetaDescription ($ this ->htmlDecoder ->inputEncodedToPlainText ($ GLOBALS ['objPage ' ]->description ));
47+ }
48+
3649 $ this ->socialTagsGenerator ->generate ($ profile );
3750 }
3851
0 commit comments