Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NGSTACK-807 handler for canonical url added #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions bundle/Handler/FieldType/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\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;
}
}
11 changes: 11 additions & 0 deletions bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ services:

netgen_open_graph.meta_tag_renderer:
class: Netgen\Bundle\OpenGraphBundle\MetaTag\Renderer

app.opengraph.handler.url:
class: Netgen\Bundle\OpenGraphBundle\Handler\FieldType\CanonicalUrl
public: false
lazy: true
arguments:
- "@router"
- '@Ibexa\Core\Helper\TranslationHelper'
- "@ibexa.api.service.content"
tags:
- { name: netgen_open_graph.meta_tag_handler, alias: app/canonical }
Loading