Skip to content

Commit

Permalink
Add more precise information about hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMilek committed Nov 4, 2024
1 parent 4adec05 commit dd9bf66
Showing 1 changed file with 139 additions and 2 deletions.
141 changes: 139 additions & 2 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ Twig Hooks are a robust and powerful alternative to the Sonata Block Events and

#### Abandoning Sonata Blocks

We are fully replacing Sonata Blocks with Twig hooks.
Sonata Blocks have been fully replaced with Twig Hooks.

#### Evolving Sylius Template Events to Twig Hooks

Expand All @@ -1418,4 +1418,141 @@ Sylius Twig Hooks is a new generation of template customization and extension, p
- A priority mechanism to control rendering order.
- Simple enable/disable options for each hook.

For more information, visit our [documentation](https://new-docs.sylius.com/).
##### Key Improvements in Sylius Twig Hooks

**Improved Structure**

Previously, all template events were configured in a single, monolithic `events.yaml` file, making it difficult to navigate and maintain:

```
/app
/config
/app
/events.yaml
```

With Twig Hooks, the configuration has been reorganized into smaller, more manageable files. Each file corresponds to a specific part of the application, enhancing clarity and maintainability:

```
/app
/config
/app
/twig_hooks
/product
/create.yaml
/update.yaml
/index.yaml
/show.yaml
```

##### Detailed Comparison: Old vs. New configurations

**Old configuration (Template Events)**

The previous approach grouped all event blocks within `events.yaml`, which led to a cluttered and hard-to-manage configuration:

```
sylius_ui:
events:
sylius.admin.index:
blocks:
before_header_legacy:
template: "@SyliusAdmin/Crud/Block/_legacySonataEvent.html.twig"
priority: 25
context:
postfix: index.before_header
header:
template: "@SyliusAdmin/Crud/Index/_header.html.twig"
priority: 20
after_header_legacy:
template: "@SyliusAdmin/Crud/Block/_legacySonataEvent.html.twig"
priority: 15
context:
postfix: index.after_header
content:
template: "@SyliusAdmin/Crud/Index/_content.html.twig"
priority: 10
after_content:
template: "@SyliusAdmin/Crud/Block/_legacySonataEvent.html.twig"
priority: 5
context:
postfix: index.after_content
```

**New configuration (Twig Hooks)**

The new system organizes hooks by specific parts of the application, simplifying customization and improving readability:

```
sylius_twig_hooks:
hooks:
'sylius_admin.common.index':
sidebar:
template: '@SyliusAdmin/shared/crud/common/sidebar.html.twig'
priority: 200
navbar:
template: '@SyliusAdmin/shared/crud/common/navbar.html.twig'
priority: 100
content:
template: '@SyliusAdmin/shared/crud/common/content.html.twig'
priority: 0
'sylius_admin.common.index.content':
flashes:
template: '@SyliusAdmin/shared/crud/common/content/flashes.html.twig'
priority: 300
header:
template: '@SyliusAdmin/shared/crud/common/content/header.html.twig'
priority: 200
grid:
template: '@SyliusAdmin/shared/crud/index/content/grid.html.twig'
priority: 100
footer:
template: '@SyliusAdmin/shared/crud/common/content/footer.html.twig'
priority: -100
'sylius_admin.common.index.content.header':
breadcrumbs:
template: '@SyliusAdmin/shared/crud/index/content/header/breadcrumbs.html.twig'
priority: 100
title_block:
template: '@SyliusAdmin/shared/crud/common/content/header/title_block.html.twig'
priority: 0
'sylius_admin.common.index.content.header.title_block':
title:
template: '@SyliusAdmin/shared/crud/common/content/header/title_block/title.html.twig'
priority: 100
actions:
template: '@SyliusAdmin/shared/crud/common/content/header/title_block/actions.html.twig'
priority: 0
'sylius_admin.common.index.content.grid':
filters:
template: '@SyliusAdmin/shared/crud/index/content/grid/filters.html.twig'
priority: 200
data_table:
template: '@SyliusAdmin/shared/crud/index/content/grid/data_table.html.twig'
priority: 100
no_data_block:
template: '@SyliusAdmin/shared/crud/index/content/grid/no_results.html.twig'
priority: 0
'sylius_admin.common.index.content.grid.no_results':
image:
template: '@SyliusAdmin/shared/crud/index/content/grid/no_results/image.html.twig'
priority: 300
title:
template: '@SyliusAdmin/shared/crud/index/content/grid/no_results/title.html.twig'
priority: 200
subtitle:
template: '@SyliusAdmin/shared/crud/index/content/grid/no_results/subtitle.html.twig'
priority: 100
action:
template: '@SyliusAdmin/shared/crud/index/content/grid/no_results/action.html.twig'
priority: 0
```

Twig Hooks cover both the admin and shop areas comprehensively, ensuring consistency across the entire application.
AdminBundle hooks start with the `sylius_admin` prefix, while ShopBundle hooks start with the `sylius_shop` prefix.

0 comments on commit dd9bf66

Please sign in to comment.