Skip to content

Commit

Permalink
Merge pull request #13 from netgen/NGSTACK-807-add-handler-for-canoni…
Browse files Browse the repository at this point in the history
…cal-url

NGSTACK-807 added handler for canonical url
  • Loading branch information
emodric authored Dec 7, 2023
2 parents e2d774c + 85e2b7c commit 8a43c60
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
39 changes: 39 additions & 0 deletions bundle/Handler/Literal/CanonicalUrl.php
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
),
];
}
}
7 changes: 7 additions & 0 deletions bundle/Resources/config/handlers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ services:
tags:
- { name: netgen_open_graph.meta_tag_handler, alias: literal/url }

netgen_open_graph.handler.literal.canonical_url:
class: Netgen\Bundle\OpenGraphBundle\Handler\Literal\CanonicalUrl
arguments:
- "@router"
tags:
- { name: netgen_open_graph.meta_tag_handler, alias: literal/canonical_url }

netgen_open_graph.handler.field_type.text_line:
class: Netgen\Bundle\OpenGraphBundle\Handler\FieldType\TextLine
parent: netgen_open_graph.handler.field_type.abstract
Expand Down

0 comments on commit 8a43c60

Please sign in to comment.