-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-3035 [Twig] Allowed passing parameters to ibexa render function
#674
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
base: 4.6
Are you sure you want to change the base?
IBX-3035 [Twig] Allowed passing parameters to ibexa render function
#674
Conversation
1bb7be8 to
2a1ab1c
Compare
| ); | ||
| } | ||
|
|
||
| public static function forwardOptionsToFragmentRenderer(MockObject $fragmentRendererMock, MockObject $valueObjectMock, string $renderStrategyClass): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This abstractions is made to avoid cut&paste of code for similar test in RenderLocationStrategyTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This abstractions is made to avoid cut&paste of code for similar test in RenderLocationStrategyTest
But does it have to be static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it needs to be static in order for RenderLocationStrategyTest to re-use the method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now replaced the static method with a trait
| if ($request->attributes->has('viewParametersString')) { | ||
| $uri->attributes['viewParametersString'] = $request->attributes->get('viewParametersString'); | ||
| } | ||
| if ($options['params'] ?? false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor this so you don't rely on true-ish expression inside of the if statement. This works because of implicit cast which can lead to some bugs under some circumstances. What is the real condition making this usable? !is_empty && is_array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rewritten and simplified the approach. Instead of adding the params parameters in the *FragmentRenders, I have instead fixed it so that the RenderStrategy object instead injects the params parameters into the ControllerReference. This is in line with what happens when render(controller()) is used
| ); | ||
| } | ||
|
|
||
| public static function forwardOptionsToFragmentRenderer(MockObject $fragmentRendererMock, MockObject $valueObjectMock, string $renderStrategyClass): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This abstractions is made to avoid cut&paste of code for similar test in RenderLocationStrategyTest
But does it have to be static?
ibexa render function
099a520 to
a0ddb17
Compare
a0ddb17 to
988d77f
Compare
ibexa render functionibexa render function
|
@vidarl please make sure all the suggestions are adressed, CI lits green and the PR is rebased. |
3c65ba0 to
5e212bb
Compare
|
| ) | ||
| ->willReturn(new Response('fragment_render_mock_rendered')); | ||
|
|
||
| $renderContentStrategy = self::createRenderStrategy( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createRenderStrategy is not a static method. Calling it statically will raise the PHP 7.4 "non-static method called statically". It could be declared as an abstract requirement in the trait to make the dependency explicit.
| $fragmentRendererMock->expects(self::once()) | ||
| ->method('render') | ||
| ->with( | ||
| self::callback(static function ($controllerReference) use ($params) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self::callback(static function ($controllerReference) use ($params) { | |
| self::callback(static function ($controllerReference) use ($params): bool { |
| 'param2' => 'value2', | ||
| ]; | ||
|
|
||
| $fragmentRendererMock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $fragmentRendererMock | |
| $fragmentRendererMock | |
| ->expects(self::once()) |
| $this->assertInstanceOf(ControllerReference::class, $controllerReference); | ||
| $this->assertEquals('ibexa_content::viewAction', $controllerReference->controller); | ||
| $this->assertSame([ | ||
| $controllerReferenceCallback = $this->callback(static function (ControllerReference $controllerReference) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $controllerReferenceCallback = $this->callback(static function (ControllerReference $controllerReference) { | |
| $controllerReferenceCallback = $this->callback(static function (ControllerReference $controllerReference): bool { |
|
|
||
| class RenderContentStrategyTest extends BaseRenderStrategyTest | ||
| { | ||
| use ForwardParamOptionsToFragmentRendererTrait; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it necessarily needs to be a Trait? Why not putting related code into BaseRenderStrategyTest?



Description:
When using
render(controller('ibexa_content::viewAction')), you can send parameters to the controller which will be available in the template.Example:
This PR adds the same possibility when using
ibexa_render():For QA:
Documentation: