From cc1dacdc201d4b927a1c958f8a41586f3554f902 Mon Sep 17 00:00:00 2001 From: Jacob Tobiasz Date: Tue, 6 Feb 2024 15:33:33 +0100 Subject: [PATCH] Convert the Inventory index page to sylius/twig-hooks --- .../Resources/config/app/template_events.yaml | 1 + .../app/twig_hooks/inventory/index.yaml | 13 +++++ .../app/twig_hooks/shared/crud/create.yaml | 0 .../app/twig_hooks/shared/crud/index.yaml | 47 +++++++++++++++++++ .../app/twig_hooks/shared/crud/show.yaml | 0 .../app/twig_hooks/shared/crud/update.yaml | 0 .../Resources/config/routing/inventory.yml | 8 +--- .../views/Inventory/Crud/index.html.twig | 3 ++ .../Header/TitleBlock/_actions.html.twig | 2 + .../Header/TitleBlock/_title.html.twig | 4 +- .../Content/Header/_titleBlock.html.twig | 17 ++++--- .../Crud/Common/Content/_header.html.twig | 19 ++++---- .../Shared/Crud/Common/_content.html.twig | 15 +++--- .../Index/Content/Grid/_dataTable.html.twig | 2 +- .../Index/Content/Grid/_filters.html.twig | 2 + .../Index/Content/Grid/_noResults.html.twig | 17 ++++--- .../Content/Header/_breadcrumbs.html.twig | 5 +- .../Shared/Crud/Index/Content/_grid.html.twig | 15 +++--- .../views/Shared/Crud/index.html.twig | 26 +++++----- .../views/Shared/Layout/base.html.twig | 4 ++ symfony.lock | 3 ++ 21 files changed, 132 insertions(+), 71 deletions(-) create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/inventory/index.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/create.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/index.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/show.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/update.yaml create mode 100644 src/Sylius/Bundle/AdminBundle/Resources/views/Inventory/Crud/index.html.twig diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/template_events.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/template_events.yaml index 3618c1e8fa..5ac925e587 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/app/template_events.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/template_events.yaml @@ -4,6 +4,7 @@ imports: - { resource: 'template_events/*.yaml' } - { resource: 'template_events/**/*.yaml' } + - { resource: 'twig_hooks/**/*.yaml' } sylius_ui: events: diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/inventory/index.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/inventory/index.yaml new file mode 100644 index 0000000000..3b41e866f9 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/inventory/index.yaml @@ -0,0 +1,13 @@ +twig_hooks: + hooks: + 'sylius_admin.inventory.index.content.header': + breadcrumbs: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Header/_breadcrumbs.html.twig' + configuration: + title: 'sylius.ui.inventory' + + 'sylius_admin.inventory.index.content.header.title_block': + title: + template: '@SyliusAdmin/Shared/Crud/Common/Content/Header/TitleBlock/_title.html.twig' + configuration: + title: 'sylius.ui.inventory' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/create.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/create.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/index.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/index.yaml new file mode 100644 index 0000000000..90d77a4a32 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/index.yaml @@ -0,0 +1,47 @@ +twig_hooks: + hooks: + 'sylius_admin.shared.crud.index': + sidebar: + template: '@SyliusAdmin/Shared/Crud/Common/_sidebar.html.twig' + navbar: + template: '@SyliusAdmin/Shared/Crud/Common/_navbar.html.twig' + content: + template: '@SyliusAdmin/Shared/Crud/Common/_content.html.twig' + + 'sylius_admin.shared.crud.index.content': + flashes: + template: '@SyliusAdmin/Shared/Crud/Common/Content/_flashes.html.twig' + header: + template: '@SyliusAdmin/Shared/Crud/Common/Content/_header.html.twig' + grid: + template: '@SyliusAdmin/Shared/Crud/Index/Content/_grid.html.twig' + + 'sylius_admin.shared.crud.index.content.header': + breadcrumbs: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Header/_breadcrumbs.html.twig' + title_block: + template: '@SyliusAdmin/Shared/Crud/Common/Content/Header/_titleBlock.html.twig' + + 'sylius_admin.shared.crud.index.content.header.title_block': + title: + template: '@SyliusAdmin/Shared/Crud/Common/Content/Header/TitleBlock/_title.html.twig' + actions: + template: '@SyliusAdmin/Shared/Crud/Common/Content/Header/TitleBlock/_actions.html.twig' + + 'sylius_admin.shared.crud.index.content.grid': + filters: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/_filters.html.twig' + data_table: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/_dataTable.html.twig' + no_data_block: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/_noResults.html.twig' + + 'sylius_admin.shared.crud.index.content.grid.no_results': + image: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/NoResults/_image.html.twig' + title: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/NoResults/_title.html.twig' + subtitle: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/NoResults/_subtitle.html.twig' + action: + template: '@SyliusAdmin/Shared/Crud/Index/Content/Grid/NoResults/_action.html.twig' diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/show.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/show.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/update.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/app/twig_hooks/shared/crud/update.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/inventory.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/inventory.yml index 345220c6e1..248e384c1a 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/inventory.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/inventory.yml @@ -4,13 +4,7 @@ sylius_admin_inventory_index: defaults: _controller: sylius.controller.product_variant::indexAction _sylius: - template: "@SyliusAdmin/Shared/Crud/index.html.twig" + template: "@SyliusAdmin/Inventory/Crud/index.html.twig" grid: sylius_admin_inventory section: admin permission: true - vars: - icon: history - templates: - breadcrumb: "@SyliusAdmin/Inventory/Index/_breadcrumb.html.twig" - header: sylius.ui.inventory - subheader: sylius.ui.manage_inventory diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Inventory/Crud/index.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Inventory/Crud/index.html.twig new file mode 100644 index 0000000000..aba23d539d --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Inventory/Crud/index.html.twig @@ -0,0 +1,3 @@ +{% extends '@SyliusAdmin/Shared/Crud/index.html.twig' %} + +{% set resource_name = 'inventory' %} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_actions.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_actions.html.twig index d30d2b9d4c..c4c90c46f8 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_actions.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_actions.html.twig @@ -1,5 +1,7 @@ {% import '@SyliusAdmin/Shared/Helper/dropdown.html.twig' as _dropdown %} +{% set resources = hookable_data.resources %} +
{% if resources.definition.actionGroups.main is defined %} {% for action in resources.definition.getEnabledActions('main') %} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_title.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_title.html.twig index a5573f4004..020b4aa35b 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_title.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/TitleBlock/_title.html.twig @@ -1,6 +1,8 @@ {% import '@SyliusAdmin/Shared/Helper/header.html.twig' as _header %} -{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.'~metadata.pluralName) %} +{% set metadata = hookable_data.metadata %} + +{% set header = hookable_configuration.title|default(metadata.applicationName~'.ui.'~metadata.pluralName) %}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/_titleBlock.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/_titleBlock.html.twig index 061bf0d083..019a8d2fd6 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/_titleBlock.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/Header/_titleBlock.html.twig @@ -1,12 +1,11 @@ -{% set main_event = twig_event_name(_context.main_event, 'title_block') %} -{% set fallback_event = twig_event_name(_context.fallback_event|default(null), 'title_block') %} +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'title_block') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'title_block') %}
- {{ twig_event( - [main_event, fallback_event], - _context|merge({ - main_event: main_event, - fallback_event: fallback_event, - }) - ) }} + {% hook [main_hook, fallback_hook] with { + parent_main_hook: main_hook, + parent_fallback_hook: fallback_hook, + metadata: hookable_data.metadata, + resources: hookable_data.resources, + } %}
diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/_header.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/_header.html.twig index 760efed693..050990107f 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/_header.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Shared/Crud/Common/Content/_header.html.twig @@ -1,14 +1,13 @@ -{% set main_event = _context.main_event ~ '.header' %} -{% set fallback_event = _context.fallback_event ~ '.header' %} +{% set main_hook = hook_name(hookable_data.parent_main_hook, 'header') %} +{% set fallback_hook = hook_name(hookable_data.parent_fallback_hook, 'header') %} -