Skip to content

Routing

Index Route

The index route is an implementation of the standard app route bound to a resource. It contains default settings for the standard Enhavo layout of resource views while still being as flexible and extendable as the app route.

Here you can see the minimum route definition, which will render the standard Enhavo layout by solely using default settings:

yaml
enhavo_page_page_index:
    path: /enhavo/page/page/index
    methods: [GET]
    defaults:
        _controller: enhavo_page.controller.page:indexAction
        _sylius:
            template: EnhavoAppBundle:Resource:index.html.twig

This is really short, isn't it? Here you can see it with all the default values spelled out:

yaml
enhavo_page_page_index:
    path: /enhavo/page/page/index
    methods: [GET]
    defaults:
        _controller: enhavo_page.controller.page:indexAction
        _sylius:
            template: EnhavoAppBundle:Resource:index.html.twig
            viewer:
                type: index
                blocks:
                    table:
                        type: table
                        table_route: enhavo_page_page_table
                        update_route: enhavo_page_page_update
                actions:
                    create:
                        type: create
                        route: enhavo_page_page_create

Create Route

The create route is being called to render the form for creating a new resource and subsequently to save the form settings.

Here is an example route displaying possible parameters:

yaml
enhavo_page_page_create:
    path: /admin/enhavo/page/page/create
    methods: [GET,POST]
    options:
        expose: true
    defaults:
        _controller: enhavo_page.controller.page:createAction
        _sylius:
            template: EnhavoAppBundle:Resource:create.html.twig
            viewer:
                type: create
                translationDomain: EnhavoPageBundle
                tabs:
                    page:
                        label: page.label.page
                        template: EnhavoContentBundle:Tab:main.html.twig
                    content:
                        label: page.label.content
                        template: EnhavoContentBundle:Tab:content.html.twig
                    meta:
                        label: page.label.meta
                        template: EnhavoContentBundle:Tab:meta.html.twig
                buttons:
                    cancel:
                        route: ~
                        display: true
                        role: ~
                        label: label.cancel
                        icon: close
                    save:
                        route: ~
                        display: true
                        role: ~
                        label: label.save
                        icon: check
                    preview:
                        route: enhavo_page_page_preview
                        display: true
                        role: ~
                        label: label.preview
                        icon: eye
                form:
                    template: EnhavoAppBundle:View:tab.html.twig
                    theme: ~
                    action: enhavo_page_page_create
                sorting:
                    sortable: false
                    position: position
                    initial: max

Update Route

yaml
enhavo_page_page_update:
    options:
        expose: true
    path: /enhavo/page/page/update/{id}
    methods: [GET,POST]
    defaults:
        _controller: enhavo_page.controller.page:updateAction
        _sylius:
            template: EnhavoAppBundle:Resource:update.html.twig
            viewer:
                type: edit
                translationDomain: EnhavoPageBundle
                tabs:
                    page:
                        label: page.label.page
                        template: EnhavoContentBundle:Tab:main.html.twig
                    content:
                        label: page.label.content
                        template: EnhavoContentBundle:Tab:content.html.twig
                    meta:
                        label: page.label.meta
                        template: EnhavoContentBundle:Tab:meta.html.twig
                buttons:
                    cancel:
                        route: ~
                        display: true
                        role: ~
                        label: label.cancel
                        icon: close
                    save:
                        route: ~
                        display: true
                        role: ~
                        label: label.save
                        icon: check
                    preview:
                        route: enhavo_page_page_preview
                        display: true
                        role: ~
                        label: label.preview
                        icon: eye
                    delete:
                        route: ~
                        display: true
                        role: ~
                        label: label.delete
                        icon: trash
                form:
                    template: EnhavoAppBundle:View:tab.html.twig
                    theme: ~
                    action: enhavo_page_page_update
                    delete: enhavo_page_page_delete

Delete Route

yaml
enhavo_page_page_delete:
    path: /admin/enhavo/page/page/delete/{id}
    defaults:
        _controller: enhavo_page.controller.page:deleteAction

Batch route

This route is needed for batch actions. These are actions that can be run on multiple items from the table view by selecting the items and choosing an action from a dropdown menu. If this route is not defined, the batch action checkboxes and dropdown menu will not be visible.

yaml
enhavo_page_page_batch:
    options:
        expose: true
    path: /enhavo/page/page/batch
    methods: [POST]
    defaults:
        _controller: enhavo_page.controller.page:batchAction

Only this one route is needed for any number of batch actions. See Guides on how to add a custom batch action.

App Route

Before you use the app route, you should know what is meant by actions and blocks. The app route is used to display these two kinds of abstractions. It is independent of any data model.

In this Picture you can see how the app route could render actions and blocks.

image

Actions

Actions are things like buttons. If you click on one of these buttons, something will be executed. For example an overlay could be displayed, which provides a form for the user to change data.

Blocks

A block is a small unit with its own logic. Its main function is to present some information, but it could also contain clickable events.

Route

Here is an example route

yaml
enhavo_page_page_app:
    path: /enhavo/page/page/app
    methods: [GET]
    defaults:
        _controller: enhavo_page.controller.page:indexAction
        _sylius:
            template: EnhavoAppBundle:App:index.html.twig
            viewer:
                type: app
                parameters:
                    name: value
                blocks:
                    table:
                        type: enhavo_page_page_table
                        parameters:
                            table_route: enhavo_page_page_table
                            update_route: enhavo_page_page_update
                actions:
                    create:
                        type: overlay
                        route: enhavo_page_page_create
                        icon: plus
                        label: label.create

Sorting Routes

A resource might be sortable, meaning it has an order which can be changed by the user. In this case, it needs two additional routes for the events of moving the object to the new position.

The move_after route handles moving the item to the position after another element, the move_to_page route allows moving an item to the top or bottom of a pagination page.

Note: If you changed the pagination value in the table route, you need to add the same value to the move_to_page route as well.


Parameters Description

_sylius.sortable_position Property of that model or row (int) which is used for sorting

_sylius.paginate If set in table route, must be set to the same value here

viewer.sorting desc (default) means higher values come before lower values, with 0 being the last element; asc is the other way around


yaml
enhavo_page_page_move_after:
    options:
        expose: true
    path: /admin/enhavo/page/page/move-after/{id}/{target}
    methods: [POST]
    defaults:
        _controller: enhavo_page.controller.slide:moveAfterAction
        _sylius:
            sortable_position: position
            viewer:
                sorting: desc
yaml
enhavo_page_page_move_to_page:
    options:
        expose: true
    path: /admin/enhavo/page/page/move-to-page/{id}/{page}/{top}
    methods: [POST]
    defaults:
        _controller: enhavo_page.controller.slide:moveToPageAction
        _sylius:
            sortable_position: position
            viewer:
                sorting: desc

Routing generator

We implemented a short routing generator, which creates minimal CRUD routing definitions for your resource.

bash
app/console enhavo:generate:routing app resource [--sorting="property"]

If the optional parameter sorting is present, the entity is considered to be sortable by the user. The value of sorting is the name of the integer property of the resource entity used to save the position of the object.