Configure your operations
Read the previous chapter to configure your resource.
Now, with your fresh new resource, you have to define the operations that you need to implement. There are some basic CRUD operations and more.
Basic operations
Index operation
Index
operation allows to browse all items of your resource.
It will configure this route for your index
operation.
app_book_index
GET
/books
On your Twig template, these variables are available
resources
Pagerfanta\Pagerfanta
books
Pagerfanta\Pagerfanta
operation
Sylius\Resource\Metadata\Index
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
Use a grid for your index operation
To use a grid for you operation, you need to install the Sylius grid package
On your Twig template, these variables are available
resources
Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView
books
Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView
operation
Sylius\Resource\Metadata\Index
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
The iterator for your books will be available as books.data
or resources.data
.
Show operation
Show
operation allows to view details of an item.
It will configure this route for your show
operation.
app_book_show
GET
/books/{id}
On your Twig template, these variables are available
resource
App\Entity\Book
book
App\Entity\Book
operation
Sylius\Resource\Metadata\Show
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
Create operation
Create
operation allows to add a new item of your resource.
It will configure this route for your create
operation.
app_book_create
GET, POST
/books/new
On your Twig template, these variables are available
resource
App\Entity\Book
book
App\Entity\Book
operation
Sylius\Resource\Metadata\Create
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
The iterator for your books will be available as books.data
or resources.data
.
Update operation
Update
operation allows to edit an existing item of your resource.
It will configure this route for your update
operation.
app_book_update
GET, PUT, PATCH
/books/{id}/edit
On your Twig template, these variables are available
resource
App\Entity\Book
book
App\Entity\Book
operation
Sylius\Resource\Metadata\Update
resource_metadata
Sylius\Resource\Metadata\ResourceMetadata
app
Symfony\Bridge\Twig\AppVariable
Delete operation
Delete
operation allows to remove an existing item of your resource.
It will configure this route for your delete
operation.
app_book_delete
DELETE
/books/{id}
Bulk delete operation
Bulk delete
operation allows to remove several items of your resource at the same time.
It will configure this route for your bulk_delete
operation.
app_book_bulk_delete
DELETE
/books/bulk_delete
State machine operation
State machine
operation allows to apply a transition to an item of your resource.
As an example, we add a publish
operation to our book resource.
It will configure this route for your apply_state_machine_transition
operation.
app_book_publish
GET
/books/{id}/publish
Advanced configuration
Configure the path
It customizes the path for your operations.
app_book_create
GET, POST
/books/register
app_book_update
GET, POST
/books/{id}/edition
Configure the short name
It customizes the path for your operations.
app_book_register
GET, POST
/books/register
It influences the path by default too, but you can still customize the path if needed.
Configure the templates' dir
It defines the templates directory for your operations.
As an example, we defines index
, create
, update
and show
operations to our book resource.
index
templates/books/index.html.twig
create
templates/books/create.html.twig
update
templates/books/update.html.twig
show
templates/books/show.html.twig
You can use @SyliusAdminUi/crud
as templates dir from the sylius/admin-ui package.
index
@SyliusAdminUi/crud/index.html.twig
create
@SyliusAdminUi/crud/create.html.twig
update
@SyliusAdminUi/crud/update.html.twig
show
@SyliusAdminUi/crud/show.html.twig
Configure the routes' prefix
It adds a prefix to the path for each operation.
app_book_index
GET
/admin/books/
app_book_create
GET, POST
/admin/books/new
app_book_update
GET, PUT, PATCH
/admin/books/{id}/edit
app_book_delete
DELETE
/admin/books/{id}
app_book_bulk_delete
DELETE
/admin/books/bulk_delete
app_book_show
GET
/admin/books/{id}
Configure the section
It changes the route name for each operation.
app_admin_book_index
GET
/admin/books/
app_admin_book_create
GET, POST
/admin/books/new
app_admin_book_update
GET, PUT, PATCH
/admin/books/{id}/edit
app_admin_book_delete
DELETE
/admin/books/{id}
app_admin_book_bulk_delete
DELETE
/admin/books/bulk_delete
app_shop_book_index
GET
/books/
app_shop_book_show
GET
/books/{id}
Configure the resource identifier
It changes the resource identifier for each operation.
app_book_index
GET
/admin/books/
app_book_create
GET, POST
/admin/books/new
app_book_update
GET, PUT, PATCH
/admin/books/{code}/edit
app_book_delete
DELETE
/admin/books/{code}
app_book_bulk_delete
DELETE
/admin/books/bulk_delete
Configure the vars
It defines the simple vars that you can use on your templates.
You can use these vars on your Twig templates. These vars will be available on any operations for this resource.
Last updated