[Admin][TwigHook] Allow configuring primary Twig hook for CRUD templates#17645
[Admin][TwigHook] Allow configuring primary Twig hook for CRUD templates#17645GSadee merged 1 commit intoSylius:2.0from
Conversation
WalkthroughThe pull request introduces a new Changes
Suggested labels
Suggested reviewers
Poem
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (7)
src/Sylius/Bundle/AdminBundle/templates/order/history.html.twig (1)
3-6: LGTM! Consider extracting common prefix to a variable.The introduction of the
prefixesarray aligns well with the PR objectives. However, since 'sylius_admin.common' is used across multiple templates, consider extracting it to a variable or constant to maintain DRY principles.src/Sylius/Bundle/AdminBundle/templates/promotion_coupon/generate.html.twig (1)
3-6: LGTM! Good use of explicit parameter naming.The changes are consistent with other templates. The explicit naming of the resource parameter (
resource: promotion) improves code clarity - this is a good practice that could be adopted in other templates as well.Also applies to: 13-13
src/Sylius/Bundle/AdminBundle/templates/shared/crud/show.html.twig (2)
3-3: Improve readability and null safety of the prefix initialization.The current ternary operation could be clearer and safer. Consider using a more explicit if-else block or the null coalescing operator.
-{% set prefixes = configuration.vars.hook_prefix is defined ? [configuration.vars.hook_prefix] %} +{% set prefixes = configuration.vars.hook_prefix is defined and configuration.vars.hook_prefix is not null + ? [configuration.vars.hook_prefix] + : [] +%}
4-7: Consider adding type hints in comments.The template uses complex data structures. Consider adding type hints in comments to improve maintainability:
+{# @var prefixes string[] #} {% set prefixes = prefixes|default({})|merge([ 'sylius_admin.%resource_name%'|replace({'%resource_name%': resource_name|default(metadata.name)}), 'sylius_admin.common' ]) %}src/Sylius/Bundle/AdminBundle/templates/shared/crud/create.html.twig (1)
3-7: Consider using array literal for default valueThe
default({})usage suggests an object, but an empty array[]would be more appropriate since we're working with arrays.-{% set prefixes = prefixes|default({})|merge([ +{% set prefixes = prefixes|default([])|merge([Additionally, consider adding documentation comments to explain the prefix structure and usage.
+{# Configures hook prefixes for CRUD templates + - Uses custom prefix from configuration.vars.hook_prefix if defined + - Adds default admin prefix with resource name + - Includes common admin hooks +#} {% set prefixes = configuration.vars.hook_prefix is defined ? [configuration.vars.hook_prefix] %}src/Sylius/Bundle/AdminBundle/templates/shared/crud/index.html.twig (2)
8-8: Remove extra empty lineThis empty line appears to be unintentional as it's not present in other templates.
3-7: Well-structured implementation for configurable hook prefixesThe implementation successfully achieves the PR objectives by:
- Maintaining backward compatibility with existing hook prefixes
- Allowing plugins/applications to customize prefixes
- Consistently applying the changes across all CRUD templates
The approach is clean and follows Sylius's template extension patterns.
Consider documenting this feature in:
- The bundle's configuration reference
- The template customization guide
- Plugin development documentation
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
src/Sylius/Bundle/AdminBundle/templates/order/history.html.twig(1 hunks)src/Sylius/Bundle/AdminBundle/templates/product/generate_variants.html.twig(1 hunks)src/Sylius/Bundle/AdminBundle/templates/promotion_coupon/generate.html.twig(1 hunks)src/Sylius/Bundle/AdminBundle/templates/shared/crud/create.html.twig(1 hunks)src/Sylius/Bundle/AdminBundle/templates/shared/crud/index.html.twig(1 hunks)src/Sylius/Bundle/AdminBundle/templates/shared/crud/show.html.twig(1 hunks)src/Sylius/Bundle/AdminBundle/templates/shared/crud/update.html.twig(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Static checks / PHP 8.3, Symfony ^7.1
- GitHub Check: Static checks / PHP 8.2, Symfony ^6.4
🔇 Additional comments (4)
src/Sylius/Bundle/AdminBundle/templates/product/generate_variants.html.twig (1)
3-6: LGTM! Implementation is consistent.The changes follow the same pattern as other templates, maintaining consistency across the codebase while enabling hook prefix configurability.
src/Sylius/Bundle/AdminBundle/templates/shared/crud/show.html.twig (1)
Line range hint
13-24: LGTM! Good separation of concerns with different hook points.The separation of hooks for the main content, stylesheets, and javascripts is well-structured and follows good practices for template organization.
src/Sylius/Bundle/AdminBundle/templates/shared/crud/update.html.twig (1)
3-7: Maintain consistency with create.html.twig changesThe same improvements suggested for create.html.twig should be applied here for consistency:
- Use
default([])instead ofdefault({})- Add documentation comments
src/Sylius/Bundle/AdminBundle/templates/shared/crud/index.html.twig (1)
3-7: Maintain consistency with other CRUD templatesThe same improvements suggested for other templates should be applied here for consistency:
- Use
default([])instead ofdefault({})- Add documentation comments
Bunnyshell Preview Environment deletedAvailable commands:
|
…ates (#277) Fixes #242 related to Sylius/Sylius#17645
By default, when using a resource controller with admin CRUD templates in plugins or applications, the hook prefix is hard coded as
sylius_admin.%resource_name%. This PR introduces the ability to configure additional prefix using a newhook_prefixoption, allowing for more flexibility in defining hook names.With this configuration. hooks related to this resource will use
sylius_refund.admin.credit_memoandsylius_admin.credit_memoSummary by CodeRabbit
prefixesvariable to manage hook references across different admin templates