From 1f9dc9f52c12d26b4a216597a203847443f4c384 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 14:20:57 +0100 Subject: [PATCH 01/12] NGSTACK-807 added handler for canonical url --- bundle/Handler/FieldType/CanonicalUrl.php | 39 +++++++++++++++++++++++ bundle/Resources/config/services.yaml | 11 +++++++ 2 files changed, 50 insertions(+) create mode 100644 bundle/Handler/FieldType/CanonicalUrl.php diff --git a/bundle/Handler/FieldType/CanonicalUrl.php b/bundle/Handler/FieldType/CanonicalUrl.php new file mode 100644 index 0000000..4f16b65 --- /dev/null +++ b/bundle/Handler/FieldType/CanonicalUrl.php @@ -0,0 +1,39 @@ +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; + } +} diff --git a/bundle/Resources/config/services.yaml b/bundle/Resources/config/services.yaml index 41103b9..3fe4e05 100644 --- a/bundle/Resources/config/services.yaml +++ b/bundle/Resources/config/services.yaml @@ -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 } From 3bf7edf7b61c3c6319b97970da75d75730d11999 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 14:26:42 +0100 Subject: [PATCH 02/12] NGSTACK-807 fixed with php-cs-fixer --- bundle/Handler/FieldType/CanonicalUrl.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bundle/Handler/FieldType/CanonicalUrl.php b/bundle/Handler/FieldType/CanonicalUrl.php index 4f16b65..8362ee1 100644 --- a/bundle/Handler/FieldType/CanonicalUrl.php +++ b/bundle/Handler/FieldType/CanonicalUrl.php @@ -5,17 +5,19 @@ 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\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; -class CanonicalUrl extends Handler +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( @@ -25,13 +27,15 @@ public function getMetaTags($tagName, array $params = []): array ], UrlGeneratorInterface::ABSOLUTE_URL, ); - return array( + + return [ new Item( $tagName, $value ), - ); + ]; } + protected function supports(Field $field): bool { return true; From 251a0a8ebbb241071c6fc4c698ec14a512b85a13 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 14:45:56 +0100 Subject: [PATCH 03/12] NGSTACK-807 tag renamed to ngsite/canonical --- bundle/Resources/config/services.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Resources/config/services.yaml b/bundle/Resources/config/services.yaml index 3fe4e05..b5e53e6 100644 --- a/bundle/Resources/config/services.yaml +++ b/bundle/Resources/config/services.yaml @@ -21,4 +21,4 @@ services: - '@Ibexa\Core\Helper\TranslationHelper' - "@ibexa.api.service.content" tags: - - { name: netgen_open_graph.meta_tag_handler, alias: app/canonical } + - { name: netgen_open_graph.meta_tag_handler, alias: ngsite/canonical } From 03fde6e5ae8ca014c1cac9e3c3b58dfc057f3bdd Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 14:51:15 +0100 Subject: [PATCH 04/12] NGSTACK-807 CanonicalUrl moved to more appropriate folder --- bundle/Handler/{FieldType => Literal}/CanonicalUrl.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename bundle/Handler/{FieldType => Literal}/CanonicalUrl.php (85%) diff --git a/bundle/Handler/FieldType/CanonicalUrl.php b/bundle/Handler/Literal/CanonicalUrl.php similarity index 85% rename from bundle/Handler/FieldType/CanonicalUrl.php rename to bundle/Handler/Literal/CanonicalUrl.php index 8362ee1..2d31147 100644 --- a/bundle/Handler/FieldType/CanonicalUrl.php +++ b/bundle/Handler/Literal/CanonicalUrl.php @@ -2,14 +2,15 @@ declare(strict_types=1); -namespace Netgen\Bundle\OpenGraphBundle\Handler\FieldType; +namespace Netgen\Bundle\OpenGraphBundle\Handler\Literal; use Ibexa\Contracts\Core\Repository\Values\Content\Field; +use Netgen\Bundle\OpenGraphBundle\Handler\FieldType\Handler; use Netgen\Bundle\OpenGraphBundle\MetaTag\Item; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RouterInterface; -class CanonicalUrl extends Handler +final class CanonicalUrl extends Handler { private RouterInterface $router; From 688c207841eadb94124c6c8334040b4f75a18aaf Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:01:21 +0100 Subject: [PATCH 05/12] NGSTACK-807 CanonicalUrl configuration fixed, 2 unnecessary arguments removed and class path fixed --- bundle/Resources/config/services.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/Resources/config/services.yaml b/bundle/Resources/config/services.yaml index b5e53e6..a510d86 100644 --- a/bundle/Resources/config/services.yaml +++ b/bundle/Resources/config/services.yaml @@ -13,12 +13,10 @@ services: class: Netgen\Bundle\OpenGraphBundle\MetaTag\Renderer app.opengraph.handler.url: - class: Netgen\Bundle\OpenGraphBundle\Handler\FieldType\CanonicalUrl + class: Netgen\Bundle\OpenGraphBundle\Handler\Literal\CanonicalUrl public: false lazy: true arguments: - "@router" - - '@Ibexa\Core\Helper\TranslationHelper' - - "@ibexa.api.service.content" tags: - { name: netgen_open_graph.meta_tag_handler, alias: ngsite/canonical } From dc3f3cb5b23ecddc00685ac2d07527e9e851456c Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:02:16 +0100 Subject: [PATCH 06/12] NGSTACK-807 public and lazy properties removed from CanonicalUrl configuration --- bundle/Resources/config/services.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/bundle/Resources/config/services.yaml b/bundle/Resources/config/services.yaml index a510d86..19b77a5 100644 --- a/bundle/Resources/config/services.yaml +++ b/bundle/Resources/config/services.yaml @@ -14,8 +14,6 @@ services: app.opengraph.handler.url: class: Netgen\Bundle\OpenGraphBundle\Handler\Literal\CanonicalUrl - public: false - lazy: true arguments: - "@router" tags: From 6e3bbc723f7640d1e24e059177e51221ab045cb0 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:05:09 +0100 Subject: [PATCH 07/12] NGSTACK-807 CanonicalUrl configuration moved to appropriate folder --- bundle/Resources/config/handlers.yaml | 7 +++++++ bundle/Resources/config/services.yaml | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bundle/Resources/config/handlers.yaml b/bundle/Resources/config/handlers.yaml index 960e8c1..122b8e7 100644 --- a/bundle/Resources/config/handlers.yaml +++ b/bundle/Resources/config/handlers.yaml @@ -55,3 +55,10 @@ services: - "@?logger" tags: - { name: netgen_open_graph.meta_tag_handler, alias: field_type/ezimage } + + 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: ngsite/canonical } diff --git a/bundle/Resources/config/services.yaml b/bundle/Resources/config/services.yaml index 19b77a5..d411b07 100644 --- a/bundle/Resources/config/services.yaml +++ b/bundle/Resources/config/services.yaml @@ -12,9 +12,4 @@ services: netgen_open_graph.meta_tag_renderer: class: Netgen\Bundle\OpenGraphBundle\MetaTag\Renderer - app.opengraph.handler.url: - class: Netgen\Bundle\OpenGraphBundle\Handler\Literal\CanonicalUrl - arguments: - - "@router" - tags: - - { name: netgen_open_graph.meta_tag_handler, alias: ngsite/canonical } + From 292d25e4db2bc361b5bab8551c3725329c0592f2 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:07:40 +0100 Subject: [PATCH 08/12] NGSTACK-807 CanonicalUrl class implements HandlerInterface insteaad of extending Handler, supports method removed --- bundle/Handler/Literal/CanonicalUrl.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bundle/Handler/Literal/CanonicalUrl.php b/bundle/Handler/Literal/CanonicalUrl.php index 2d31147..f5e747b 100644 --- a/bundle/Handler/Literal/CanonicalUrl.php +++ b/bundle/Handler/Literal/CanonicalUrl.php @@ -4,13 +4,12 @@ namespace Netgen\Bundle\OpenGraphBundle\Handler\Literal; -use Ibexa\Contracts\Core\Repository\Values\Content\Field; -use Netgen\Bundle\OpenGraphBundle\Handler\FieldType\Handler; +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 extends Handler +final class CanonicalUrl implements HandlerInterface { private RouterInterface $router; @@ -36,9 +35,4 @@ public function getMetaTags($tagName, array $params = []): array ), ]; } - - protected function supports(Field $field): bool - { - return true; - } } From dabbd62ec30487b7f7e32dd1ce39efe26b318661 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:09:46 +0100 Subject: [PATCH 09/12] NGSTACK-807 tag renamed to literal/canonical_url --- bundle/Resources/config/handlers.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/Resources/config/handlers.yaml b/bundle/Resources/config/handlers.yaml index 122b8e7..62635ad 100644 --- a/bundle/Resources/config/handlers.yaml +++ b/bundle/Resources/config/handlers.yaml @@ -61,4 +61,4 @@ services: arguments: - "@router" tags: - - { name: netgen_open_graph.meta_tag_handler, alias: ngsite/canonical } + - { name: netgen_open_graph.meta_tag_handler, alias: literal/canonical_url } From 0cd17d86e40783d873780eef72558c0034c9bdc4 Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:27:28 +0100 Subject: [PATCH 10/12] NGSTACK-807 canonical tag configuration moved closer to other literal configurations --- bundle/Resources/config/handlers.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bundle/Resources/config/handlers.yaml b/bundle/Resources/config/handlers.yaml index 62635ad..3405c7f 100644 --- a/bundle/Resources/config/handlers.yaml +++ b/bundle/Resources/config/handlers.yaml @@ -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 @@ -55,10 +62,3 @@ services: - "@?logger" tags: - { name: netgen_open_graph.meta_tag_handler, alias: field_type/ezimage } - - 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 } From 5d5f31cbbaab64390c1a080361eace2723e7ebba Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:28:57 +0100 Subject: [PATCH 11/12] NGSTACK-807 extra whitespaces removed --- bundle/Resources/config/services.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/bundle/Resources/config/services.yaml b/bundle/Resources/config/services.yaml index d411b07..41103b9 100644 --- a/bundle/Resources/config/services.yaml +++ b/bundle/Resources/config/services.yaml @@ -11,5 +11,3 @@ services: netgen_open_graph.meta_tag_renderer: class: Netgen\Bundle\OpenGraphBundle\MetaTag\Renderer - - From 85e2b7cb3358da82a10f949cd1c8d477229becab Mon Sep 17 00:00:00 2001 From: Miljenko Muha Date: Thu, 7 Dec 2023 15:42:57 +0100 Subject: [PATCH 12/12] NGSTACK-807 ibexa alias string replaced with constant --- bundle/Handler/Literal/CanonicalUrl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle/Handler/Literal/CanonicalUrl.php b/bundle/Handler/Literal/CanonicalUrl.php index f5e747b..3a86261 100644 --- a/bundle/Handler/Literal/CanonicalUrl.php +++ b/bundle/Handler/Literal/CanonicalUrl.php @@ -4,6 +4,7 @@ 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; @@ -21,7 +22,7 @@ public function __construct(RouterInterface $router) public function getMetaTags($tagName, array $params = []): array { $value = $this->router->generate( - 'ibexa.url.alias', + UrlAliasRouter::URL_ALIAS_ROUTE_NAME, [ 'locationId' => $this->content->contentInfo->mainLocationId, ],