Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ services:
eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\QueryRenderingExtension:
arguments:
- '@fragment.handler'
- '@request_stack'
tags:
- { name: twig.extension }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace eZ\Publish\Core\MVC\Symfony\Templating\Tests\Twig\Extension;

use eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\QueryRenderingExtension;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;

final class QueryRenderingExtensionTest extends FileSystemTwigIntegrationTestCase
Expand All @@ -22,8 +24,18 @@ protected function getExtensions(): array
return var_export($args, true);
});

$currentRequest = $this->createMock(Request::class);
$currentRequest
->method('get')
->willReturn(1);

$requestStack = $this->createMock(RequestStack::class);
$requestStack
->method('getCurrentRequest')
->willReturn($currentRequest);

return [
new QueryRenderingExtension($fragmentHandler),
new QueryRenderingExtension($fragmentHandler, $requestStack),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ array (
),
'query' =>
array (
'page' => 1,
),
)),
1 => 'inline',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ array (
),
'query' =>
array (
'page' => 1,
),
)),
1 => 'esi',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
"ez_render_content_query_b" function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean ez_render_content_query?

--TEMPLATE--
{{ ez_render_content_query({
'query': {
'query_type': 'LatestBlogPost',
},
'pagination': {
'enabled': true,
'limit': 5,
'page_param' : 'current_page'
},
'template': 'latest_blog_post.html.twig',
}) }}
--DATA--
return array()
--EXPECT--
array (
0 =>
Symfony\Component\HttpKernel\Controller\ControllerReference::__set_state(array(
'controller' => 'ez_query_render::renderQuery',
'attributes' =>
array (
'options' =>
array (
'query' =>
array (
'query_type' => 'LatestBlogPost',
),
'pagination' =>
array (
'enabled' => true,
'limit' => 5,
'page_param' => 'current_page',
),
'template' => 'latest_blog_post.html.twig',
),
),
'query' =>
array (
'current_page' => 1,
),
)),
1 => 'inline',
2 =>
array (
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ array (
),
'query' =>
array (
'page' => 1,
),
)),
1 => 'inline',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ array (
),
'query' =>
array (
'page' => 1,
),
)),
1 => 'esi',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension;

use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Twig\Extension\AbstractExtension;
Expand All @@ -21,9 +22,13 @@ class QueryRenderingExtension extends AbstractExtension
/** @var \Symfony\Component\HttpKernel\Fragment\FragmentHandler */
private $fragmentHandler;

public function __construct(FragmentHandler $fragmentHandler)
/** @var \Symfony\Component\HttpFoundation\RequestStack */
private $requestStack;

public function __construct(FragmentHandler $fragmentHandler, RequestStack $requestStack)
{
$this->fragmentHandler = $fragmentHandler;
$this->requestStack = $requestStack;
}

public function getFunctions(): array
Expand Down Expand Up @@ -57,9 +62,15 @@ function (string $type, string $renderer, array $options): ?string {

private function createControllerReference(array $options): ControllerReference
{
return new ControllerReference('ez_query_render::renderQuery', [
'options' => $options,
]);
$pageParam = $options['pagination']['page_param'] ?? 'page';

return new ControllerReference(
'ez_query_render::renderQuery',
[
'options' => $options,
],
[$pageParam => $this->requestStack->getCurrentRequest()->get($pageParam)],
);
}

/**
Expand Down