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

[TwigHooks][RFC] improving the DX #167

Open
loic425 opened this issue Dec 13, 2024 · 2 comments
Open

[TwigHooks][RFC] improving the DX #167

loic425 opened this issue Dec 13, 2024 · 2 comments

Comments

@loic425
Copy link
Member

loic425 commented Dec 13, 2024

Before

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
    $container->extension('sylius_twig_hooks', [
        'hooks' => [
            'sylius_admin.book.show.content' => [
                'body' => [
                    'template' => 'library/book/show/content/body.html.twig',
                    'priority' => 100,
                ],
                 'dropdown' => [
                    'component' => DropdownComponent::class,
                    'priority' => 0,
                    'props' => [],
                ],
            ],
        ],
    ]);
};

After

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (TwigHooksConfig $config): void {
    $config->withHook(
        (new Hook('sylius_admin.book.show.content'))
            ->withHookable(
                (new HookableTemplate('body', 'library/book/show/content/body.html.twig'))
                    ->withPriority(100)
            )     
            ->withHookable(
                (new HookableComponent('dropdown', DropdownComponent::class))
                    ->withProps([])
                    ->withPriority(0)
            )     
    );
};

Going further on resource operation
Then we could go further and configure them on a specific resource operation.

#[AsResource(
   //...
    operations: [
        new Show(provider: BookItemProvider::class, hooks: [
             (new Hook('sylius_admin.book.show.content'))
                ->withHookable(
                    (new HookableTemplate('body', 'library/book/show/content/body.html.twig'))
                        ->withPriority(100)
                )     
                ->withHookable(
                    (new HookableComponent('dropdown', DropdownComponent::class))
                        ->withProps([])
                        ->withPriority(0)
                ) 
            ]),
    ],
)]
class ShowBookResource implements ResourceInterface

Note: In userland, we do not need to configure a lot of Twig hooks for our custom operations.

@loic425 loic425 changed the title [TwigHooks] improving the DX [TwigHooks][RFC] improving the DX Dec 17, 2024
@diimpp
Copy link
Member

diimpp commented Jan 30, 2025

Only comment, that hook and hookable are other way around.

--- (new Hookable('sylius_admin.book.show.content'))
+++ (new Hook('sylius_admin.book.show.content'))
---                ->withHook(
+++                ->withHookable(
---                    (new TemplateHook('body', 'library/book/show/content/body.html.twig'))
+++                    (new HookableTemplate('body', 'library/book/show/content/body.html.twig'))
                        ->withPriority(100)
                )

@loic425
Copy link
Member Author

loic425 commented Jan 30, 2025

@diimpp You are right, I always revert the hook & hookable in my head. I've updated the RFC.

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

No branches or pull requests

2 participants