-
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.
Merge pull request #13 from netgen/NGSTACK-807-add-handler-for-canoni…
…cal-url NGSTACK-807 added handler for canonical url
- Loading branch information
Showing
2 changed files
with
46 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\Literal; | ||
|
||
use Ibexa\Core\MVC\Symfony\Routing\UrlAliasRouter; | ||
use Netgen\Bundle\OpenGraphBundle\Handler\HandlerInterface; | ||
use Netgen\Bundle\OpenGraphBundle\MetaTag\Item; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
final class CanonicalUrl implements HandlerInterface | ||
{ | ||
private RouterInterface $router; | ||
|
||
public function __construct(RouterInterface $router) | ||
{ | ||
$this->router = $router; | ||
} | ||
|
||
public function getMetaTags($tagName, array $params = []): array | ||
{ | ||
$value = $this->router->generate( | ||
UrlAliasRouter::URL_ALIAS_ROUTE_NAME, | ||
[ | ||
'locationId' => $this->content->contentInfo->mainLocationId, | ||
], | ||
UrlGeneratorInterface::ABSOLUTE_URL, | ||
); | ||
|
||
return [ | ||
new Item( | ||
$tagName, | ||
$value | ||
), | ||
]; | ||
} | ||
} |
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