[go: nahoru, domu]

Skip to content
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

Create action and filter context factories #338

Conversation

loic425
Copy link
Member
@loic425 loic425 commented Jul 19, 2024

In Sylius resource bundle, a Twig Grid renderer decorates the grid one in order to add some data to the context (Twig context here but the renderer does not depends on Twig).

Cause I need to add things on resource side to this context, I think it will be easier to allow decorating that context instead.

Example for the future in Resource package to improve that https://github.com/Sylius/SyliusResourceBundle/blob/1.11/src/Bundle/Grid/Renderer/TwigGridRenderer.php#L64

final class ActionContextFactory implemented ActionContextFactoryInterface
{
    public function __construct(
        private ActionContextFactoryInterface $contextFactory,
        private OptionsParserInterface $optionsParser,
    ) {
    }

    public function create(GridViewInterface $gridView, Action $action, mixed $data = null): array
    {
        $options = $this->optionsParser->parseOptions(
            $action->getOptions(),
            $gridView->getRequestConfiguration()->getRequest(),
            $data,
        );

        return array_merge($this->contextFactory->create($grid, $action, $data), [
            'grid' => $gridView,
            'action' => $action,
            'data' => $data,
            'options' => $options,
        ]);
    }
}

Cause I will also need to add new context data when using the new routing system.

Copy link
Member
@diimpp diimpp left a comment

Choose a reason for hiding this comment

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

(I'm just thinking out load, it's not a call to action.)

It's a bit strange to have Context/Factory/ActionContextFactoryInterface, but no actual ActionContext as "context" is array and no factoring is happening.

It's more like formatter or provider.

Is there any point adding parameter bag as in TwigHooks for that?

Comment on lines +76 to +77


Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Comment on lines 16 to 20
<import resource="services/field_types.xml" />
<import resource="services/filters.xml" />
<import resource="services/renderer_context.xml" />
<import resource="services/templating.xml" />
<import resource="services/twig.xml" />
Copy link
Member

Choose a reason for hiding this comment

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

Just an idea, this approach is less error prone, less code and seems what sylius uses in newer bundles, like ApiBundle.

Suggested change
<import resource="services/field_types.xml" />
<import resource="services/filters.xml" />
<import resource="services/renderer_context.xml" />
<import resource="services/templating.xml" />
<import resource="services/twig.xml" />
<import resource="services/*.xml" />
Suggested change
<import resource="services/field_types.xml" />
<import resource="services/filters.xml" />
<import resource="services/renderer_context.xml" />
<import resource="services/templating.xml" />
<import resource="services/twig.xml" />
<import resource="services/**/*.xml" />

https://github.com/Sylius/Sylius/blob/b7d92a66caed63094d820296d20d00a1bee0ed04/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml#L18-L20


<service id="sylius.grid.renderer.context.factory.filter" class="Sylius\Component\Grid\Renderer\Context\Factory\FilterContextFactory" />
<service id="Sylius\Component\Grid\Renderer\Context\Factory\FilterContextFactoryInterface" alias="sylius.grid.renderer.context.factory.filter" />

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@loic425
Copy link
Member Author
loic425 commented Aug 4, 2024

(I'm just thinking out load, it's not a call to action.)

It's a bit strange to have Context/Factory/ActionContextFactoryInterface, but no actual ActionContext as "context" is array and no factoring is happening.

It's more like formatter or provider.

Interesting solution here https://github.com/symfony/symfony/blob/7.2/src/Symfony/Component/Serializer/Context/ContextBuilderInterface.php

@loic425 loic425 closed this Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants