Skip to content

Commit d26c5ee

Browse files
authored
Merge pull request #2162 from M0rgan01/Document-the-_parent-route-attribute-for-tab-less-routes
2 parents c4d1ead + c295e80 commit d26c5ee

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

development/architecture/modern/controller-routing.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,40 @@ admin_emails:
294294
- AdminEmails:list
295295
```
296296

297+
#### Tab resolution for tab-less routes
298+
299+
Some routes have no `Tab` of their own. The create, edit, and view actions of an entity are usually reached only from the entity's listing page and don't need a separate menu entry. Without a `Tab`, the sidebar has nothing to highlight, and the breadcrumb and toolbar have nothing to resolve against.
300+
301+
Use the `_parent` attribute to declare which other route's `Tab` these actions should borrow:
302+
303+
```yaml
304+
admin_foo_index:
305+
path: /foo
306+
methods: [GET]
307+
defaults:
308+
_controller: 'PrestaShopBundle\Controller\Path\To\FooController::indexAction'
309+
310+
admin_foo_create:
311+
path: /foo/create
312+
methods: [GET, POST]
313+
defaults:
314+
_controller: 'PrestaShopBundle\Controller\Path\To\FooController::createAction'
315+
_parent: admin_foo_index
316+
317+
admin_foo_edit:
318+
path: /foo/{fooId}/edit
319+
methods: [GET, POST]
320+
defaults:
321+
_controller: 'PrestaShopBundle\Controller\Path\To\FooController::editAction'
322+
_parent: admin_foo_index
323+
```
324+
325+
`_parent` names another route, typically the listing route of the same entity. When the current route has no related `Tab` in the database, the sidebar, breadcrumb, and toolbar fall back to the `Tab` of the route named in `_parent`.
326+
327+
{{% notice warning %}}
328+
Do not add `_legacy_controller` to a route only to make the sidebar or breadcrumb work. `_legacy_controller` is reserved for controllers actually migrated from a legacy `AdminXController`: it also drives permission checks and `Link::getAdminLink()` resolution. Removing it from a migrated page breaks both. A route counts as native, whether it's declared by the core or by a module, as soon as it has no legacy `AdminXController` behind it. For a native route, use `_parent` instead. It has no effect on permissions or link generation: it's purely used for Back Office navigation rendering.
329+
{{% /notice %}}
330+
297331
#### Automatic redirection
298332

299333
Finally some urls might have been generated manually or hard coded. To avoid losing these legacy urls a Symfony listener

0 commit comments

Comments
 (0)