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 · 0 comments
Open

[TwigHooks][RFC] improving the DX #167

loic425 opened this issue Dec 13, 2024 · 0 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;

use function Sylius\TwigHooks\Loader\Configurator\component_hook;
use function Sylius\TwigHooks\Loader\Configurator\template_hook;

return static function (TwigHooksConfig $config): void {
    $config->withHookable(
        (new Hookable('sylius_admin.book.show.content'))
            ->withHook(
                (new TemplateHook('body', 'library/book/show/content/body.html.twig'))
                    ->withPriority(100)
            )     
            ->withHook(
                (new ComponentHook('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 Hookable('sylius_admin.book.show.content'))
                ->withHook(
                    (new TemplateHook('body', 'library/book/show/content/body.html.twig'))
                        ->withPriority(100)
                )     
                ->withHook(
                    (new ComponentHook('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
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

1 participant