Skip to content

Conversation

@vidarl
Copy link
Contributor

@vidarl vidarl commented Nov 3, 2025

🎫 Issue IBX-3035

Description:

When using render(controller('ibexa_content::viewAction')), you can send parameters to the controller which will be available in the template.

Example:

    <h2>render controller</h2>
    {{ render(controller('ibexa_content::viewAction', {
        'contentId': content.id,
        'viewType': 'line',
        'params':
            { 'my_param': 'custom_data', }
    })) }}

    <h2>render_esi controller</h2>
    {{ render_esi(controller('ibexa_content::viewAction', {
        'contentId': content.id,
        'viewType': 'line',
        'params':
            { 'my_param': 'custom_data', }
    })) }}

This PR adds the same possibility when using ibexa_render() :

    <h2>direct</h2>
    {{ ibexa_render(content,
        {
            'viewType': 'line',
            'method': 'direct',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

    {{ ibexa_render(location,
        {
            'viewType': 'line',
            'method': 'direct',
            'params': {
            'my_param': 'custom_data'
        }
        })
    }} <br/>

    <h2>inline</h2>
    {{ ibexa_render(content,
        {
            'viewType': 'line',
            'method': 'inline',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

    {{ ibexa_render(location,
        {
            'viewType': 'line',
            'method': 'inline',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>


    <h2>esi</h2>
    {{ ibexa_render(content,
        {
            'viewType': 'line',
            'method': 'esi',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

    {{ ibexa_render(location,
        {
            'viewType': 'line',
            'method': 'esi',
            'params': {
                'my_param': 'custom_data'
            }
        })
    }} <br/>

For QA:

Documentation:

@mnocon mnocon added the Doc needed The changes require some documentation label Nov 4, 2025
@vidarl vidarl force-pushed the IBX-3035_As_a_developer_I_want_to_pass_extra_atrributes_when_using_ibexa_render_Twig_function branch 3 times, most recently from 1bb7be8 to 2a1ab1c Compare November 4, 2025 15:06
);
}

public static function forwardOptionsToFragmentRenderer(MockObject $fragmentRendererMock, MockObject $valueObjectMock, string $renderStrategyClass): void
Copy link
Contributor Author

@vidarl vidarl Nov 4, 2025

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

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

@vidarl vidarl Dec 2, 2025

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) {
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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?

@alongosz alongosz changed the title IBX-3035 as a developer i want to pass extra atrributes when using ibexa render_twig() function IBX-3035: [Twig] Allowed passing parameters to ibexa render function Nov 5, 2025
@vidarl vidarl force-pushed the IBX-3035_As_a_developer_I_want_to_pass_extra_atrributes_when_using_ibexa_render_Twig_function branch from 2a1ab1c to 8cecc06 Compare November 27, 2025 14:19
@vidarl vidarl force-pushed the IBX-3035_As_a_developer_I_want_to_pass_extra_atrributes_when_using_ibexa_render_Twig_function branch from 099a520 to a0ddb17 Compare December 1, 2025 14:55
@vidarl vidarl requested a review from alongosz December 2, 2025 08:07
@vidarl vidarl force-pushed the IBX-3035_As_a_developer_I_want_to_pass_extra_atrributes_when_using_ibexa_render_Twig_function branch from a0ddb17 to 988d77f Compare December 2, 2025 08:10
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Doc needed The changes require some documentation Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants