Skip to content

Commit

Permalink
IBX-4598: Added support for generating urls for content wrappers in i…
Browse files Browse the repository at this point in the history
…bexa_url/ibexa_path (#181)
  • Loading branch information
adamwojs authored and ciastektk committed Sep 4, 2023
1 parent 9c53b7f commit 8a7b1e9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/contracts/Repository/Values/Content/ContentAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Core\Repository\Values\Content;

interface ContentAwareInterface
{
public function getContent(): Content;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\Core\MVC\Symfony\Templating\Twig\Extension;

use Ibexa\Contracts\Core\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Ibexa\Core\MVC\Symfony\Routing\Generator\RouteReferenceGeneratorInterface;
Expand Down Expand Up @@ -125,6 +126,11 @@ private function generateUrlForObject(object $object, array $parameters, int $re
$parameters += [
'contentId' => $object->id,
];
} elseif ($object instanceof ContentAwareInterface) {
$routeName = UrlAliasRouter::URL_ALIAS_ROUTE_NAME;
$parameters += [
'contentId' => $object->getContent()->getVersionInfo()->getContentInfo()->id,
];
} elseif ($object instanceof RouteReference) {
$routeName = $object->getRoute();
$parameters += $object->getParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension;

use Ibexa\Contracts\Core\Repository\Values\Content\Content as APIContent;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Location as APILocation;
use Ibexa\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator;
Expand Down Expand Up @@ -51,6 +52,14 @@ protected function getExampleContent(int $id): APIContent
]);
}

protected function getExampleContentAware(int $id): ContentAwareInterface
{
$contentAware = $this->createMock(ContentAwareInterface::class);
$contentAware->method('getContent')->willReturn($this->getExampleContent($id));

return $contentAware;
}

protected function getExampleContentInfo(int $id): ContentInfo
{
return new ContentInfo([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instea
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 14.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 15.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 16.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 17.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 18.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 19.
--TEMPLATE--
{{ ez_path(location) }}
{{ ez_path(location, {}, true) }}
Expand All @@ -26,6 +29,9 @@ Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instea
{{ ez_path(content_info) }}
{{ ez_path(content_info, {}, true) }}
{{ ez_path(content_info, {'foo': 'foo'}) }}
{{ ez_path(content_aware) }}
{{ ez_path(content_aware, {}, true) }}
{{ ez_path(content_aware, {'foo': 'foo'}) }}
{{ ez_path(route_ref) }}
{{ ez_path(route_ref, {}, true) }}
{{ ez_path(route_ref, {'baz': 'baz'}) }}
Expand All @@ -37,6 +43,7 @@ return [
'location' => $this->getExampleLocation(54),
'content' => $this->getExampleContent(2),
'content_info' => $this->getExampleContentInfo(2),
'content_aware' => $this->getExampleContentAware(64),
'route_ref' => $this->getExampleRouteReference(
'example_route',
[
Expand All @@ -56,6 +63,9 @@ return [
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":1}
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":2}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":2},"$referenceType":1}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":1}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":2}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":64},"$referenceType":1}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":1}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":2}
{"$name":"example_route","$parameters":{"baz":"baz","foo":"foo","bar":"bar"},"$referenceType":1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 11.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 12.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 13.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 14.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 15.
Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instead in index.twig at line 16.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 14.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 15.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 16.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 17.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 18.
Twig Function "ez_url" is deprecated since version 4.0. Use "ibexa_url" instead in index.twig at line 19.
--TEMPLATE--
{{ ez_url(location) }}
{{ ez_url(location, {}, true) }}
Expand All @@ -26,17 +29,21 @@ Twig Function "ez_path" is deprecated since version 4.0. Use "ibexa_path" instea
{{ ez_url(content_info) }}
{{ ez_url(content_info, {}, true) }}
{{ ez_url(content_info, {'foo': 'foo'}) }}
{{ ez_url(content_aware) }}
{{ ez_url(content_aware, {}, true) }}
{{ ez_url(content_aware, {'foo': 'foo'}) }}
{{ ez_url(route_ref) }}
{{ ez_url(route_ref, {}, true) }}
{{ ez_url(route_ref, {'baz': 'baz'}) }}
{{ ez_path(unsupported_object) }}
{{ ez_path(unsupported_object, {}, true) }}
{{ ez_path(unsupported_object, {'baz': 'baz'}) }}
{{ ez_url(unsupported_object) }}
{{ ez_url(unsupported_object, {}, true) }}
{{ ez_url(unsupported_object, {'baz': 'baz'}) }}
--DATA--
return [
'location' => $this->getExampleLocation(54),
'content' => $this->getExampleContent(2),
'content_info' => $this->getExampleContentInfo(2),
'content_aware' => $this->getExampleContentAware(64),
'route_ref' => $this->getExampleRouteReference(
'example_route',
[
Expand All @@ -56,9 +63,12 @@ return [
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":0}
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":3}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":2},"$referenceType":0}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":0}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":3}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":64},"$referenceType":0}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":0}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":3}
{"$name":"example_route","$parameters":{"baz":"baz","foo":"foo","bar":"bar"},"$referenceType":0}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":1}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":2}
{"$name":"","$parameters":{"baz":"baz","_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":1}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":0}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":3}
{"$name":"","$parameters":{"baz":"baz","_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":0}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
{{ ibexa_path(content_info) }}
{{ ibexa_path(content_info, {}, true) }}
{{ ibexa_path(content_info, {'foo': 'foo'}) }}
{{ ibexa_path(content_aware) }}
{{ ibexa_path(content_aware, {}, true) }}
{{ ibexa_path(content_aware, {'foo': 'foo'}) }}
{{ ibexa_path(route_ref) }}
{{ ibexa_path(route_ref, {}, true) }}
{{ ibexa_path(route_ref, {'baz': 'baz'}) }}
Expand All @@ -21,6 +24,7 @@ return [
'location' => $this->getExampleLocation(54),
'content' => $this->getExampleContent(2),
'content_info' => $this->getExampleContentInfo(2),
'content_aware' => $this->getExampleContentAware(64),
'route_ref' => $this->getExampleRouteReference(
'example_route',
[
Expand All @@ -40,6 +44,9 @@ return [
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":1}
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":2}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":2},"$referenceType":1}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":1}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":2}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":64},"$referenceType":1}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":1}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":2}
{"$name":"example_route","$parameters":{"baz":"baz","foo":"foo","bar":"bar"},"$referenceType":1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
{{ ibexa_url(content_info) }}
{{ ibexa_url(content_info, {}, true) }}
{{ ibexa_url(content_info, {'foo': 'foo'}) }}
{{ ibexa_url(content_aware) }}
{{ ibexa_url(content_aware, {}, true) }}
{{ ibexa_url(content_aware, {'foo': 'foo'}) }}
{{ ibexa_url(route_ref) }}
{{ ibexa_url(route_ref, {}, true) }}
{{ ibexa_url(route_ref, {'baz': 'baz'}) }}
{{ ibexa_path(unsupported_object) }}
{{ ibexa_path(unsupported_object, {}, true) }}
{{ ibexa_path(unsupported_object, {'baz': 'baz'}) }}
{{ ibexa_url(unsupported_object) }}
{{ ibexa_url(unsupported_object, {}, true) }}
{{ ibexa_url(unsupported_object, {'baz': 'baz'}) }}
--DATA--
return [
'location' => $this->getExampleLocation(54),
'content' => $this->getExampleContent(2),
'content_info' => $this->getExampleContentInfo(2),
'content_aware' => $this->getExampleContentAware(64),
'route_ref' => $this->getExampleRouteReference(
'example_route',
[
Expand All @@ -40,9 +44,12 @@ return [
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":0}
{"$name":"ibexa.url.alias","$parameters":{"contentId":2},"$referenceType":3}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":2},"$referenceType":0}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":0}
{"$name":"ibexa.url.alias","$parameters":{"contentId":64},"$referenceType":3}
{"$name":"ibexa.url.alias","$parameters":{"foo":"foo","contentId":64},"$referenceType":0}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":0}
{"$name":"example_route","$parameters":{"foo":"foo","bar":"bar"},"$referenceType":3}
{"$name":"example_route","$parameters":{"baz":"baz","foo":"foo","bar":"bar"},"$referenceType":0}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":1}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":2}
{"$name":"","$parameters":{"baz":"baz","_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":1}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":0}
{"$name":"","$parameters":{"_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":3}
{"$name":"","$parameters":{"baz":"baz","_route_object":{"foo":"foo","bar":"bar"}},"$referenceType":0}

0 comments on commit 8a7b1e9

Please sign in to comment.