Skip to content

Commit 2a1c9a4

Browse files
committed
Provide contact profile detail information using the response context
1 parent e4057c3 commit 2a1c9a4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/EventListener/DetailPageListener.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace Hofff\Contao\ContactProfiles\EventListener;
66

77
use 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;
811
use Contao\StringUtil;
912
use Hofff\Contao\ContactProfiles\Event\ProfileDetailPageEvent;
1013
use 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

src/Resources/config/listener.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
<argument type="service" id="contao.insert_tag.parser"/>
146146
<argument type="service" id="Hofff\Contao\ContactProfiles\SocialTags\SocialTagsGenerator"/>
147147
<tag name="kernel.event_listener" event="hofff.contao_contact_profile.profile_detail_page"/>
148+
<argument type="service" id="contao.routing.response_context_accessor"/>
149+
<argument type="service" id="contao.string.html_decoder"/>
148150
</service>
149151

150152
<service id="Hofff\Contao\ContactProfiles\EventListener\MultilingualListener">

0 commit comments

Comments
 (0)