-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NGSTACK-807 handler for canonical url added
- Loading branch information
Miljenko Muha
committed
Dec 7, 2023
1 parent
e2d774c
commit 1458f49
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netgen\Bundle\OpenGraphBundle\Handler\FieldType; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Field; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Netgen\Bundle\OpenGraphBundle\MetaTag\Item; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
class CanonicalUrl extends Handler | ||
{ | ||
private RouterInterface $router; | ||
public function __construct(RouterInterface $router) | ||
{ | ||
$this->router = $router; | ||
} | ||
public function getMetaTags($tagName, array $params = []): array | ||
{ | ||
$value = $this->router->generate( | ||
'ibexa.url.alias', | ||
[ | ||
'locationId' => $this->content->contentInfo->mainLocationId, | ||
], | ||
UrlGeneratorInterface::ABSOLUTE_URL, | ||
); | ||
return array( | ||
new Item( | ||
$tagName, | ||
$value | ||
), | ||
); | ||
} | ||
protected function supports(Field $field): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters