Creating automatic crud grid and actions with Sylius (Symfony bundle) - grid

I tried to use Sylius Grid system to make my articles management easy.
So, I followed the Sylius doc and I see the grid with my articles displayed. Then I've added action buttons but when I want to use them, I have an error (only for edit and create. Delete works well): Class "form" is not configured for resource "blog.article".
I understand that it can't find any FormClass to render my Article, but there is not this information in the doc, and I think I saw on a doc (I don't remember which) that the form is rendered automatically according to the Entity.
Here is my code :
Declaration of the resource :
sylius_resource:
resources:
blog.article:
driver: doctrine/orm
classes:
model: BlogBundle\Entity\Article
The grid config :
sylius_grid:
grids:
blog_admin_article:
driver:
name: doctrine/orm
options:
class: BlogBundle\Entity\Article
sorting:
date: asc
fields:
titre:
type: string
label: sylius.ui.title
sortable: ~
date:
type: datetime
label: sylius.ui.date
sortable: ~
resume:
type: string
label: sylius.ui.resume
sortable: ~
filters:
search:
type: string
label: sylius.ui.search
options:
fields: [titre, resume ]
actions:
main:
create:
type: create
label: sylius.ui.create
item:
update:
type: update
delete:
type: delete
show:
type: show
The route :
blog_admin_article:
resource: |
alias: blog.article
section: admin
templates: SyliusAdminBundle:Crud
except: ['show']
redirect: update
grid: blog_admin_article
vars:
all:
subheader: blog.ui.articles.subtitle
index:
icon: 'newspaper icon'
type: sylius.resource
Does anyone know what is the problem ?
Thanks for your help !

Since the autogeneration of forms was disabled in the beta1, there are 2 ways to solve your problem:
Create and declare your own form type like here in the docs (ArticleType).
Use dev-master branch of Sylius instead of beta1, where the autogeneration is back.

Related

Sylius Some mandatory parameters are missing when trying to generate create's view

I have a related with product entity and need to have product's id in the url, like /admin/products/{productId}/new-entity. I'm struggling with the following error:
An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("productId") to generate a URL for route "app_admin_something_related_to_product_index"."). It's throwed when I click create's button. I found here a similar problem but the solution didn't help me. I finished with trying to overwrite some templates but they weren't applied. Does anyone kwon how can I handle it?
routes.yaml
app_admin_something_related_to_product:
resource: |
alias: app.something_related_to_product
section: admin
templates: "#SyliusAdmin\\Crud"
grid: app_admin_something_related_to_product
vars:
all:
subheader: xxx
index:
icon: ~
type: sylius.resource
prefix: /admin/products/{productId}
routes.yaml:
app_admin_something_related_to_product_create:
path: /admin/products/{productId}/something-related-to-product/new
methods: [GET, POST]
defaults:
_controller: app.controller.something_related_to_product:createAction
_sylius:
section: admin
factory:
method: createNew
arguments:
- expr:notFoundOnNull(service('sylius.repository.product').find($productId))
template: "#SyliusAdmin/Crud/create.html.twig"
grid: app_admin_something_related_to_product
redirect:
route: app_admin_something_related_to_product_index
parameters:
productId: $productId
parameters: { productId: $productId }
permission: true
vars:
route:
parameters:
productId: $productId
templates:
form: "#SyliusAdmin/ProductVariant/_form.html.twig"
breadcrumb: "#SyliusAdmin/ProductVariant/Create/_breadcrumb.html.twig"
header_title: "#SyliusAdmin/ProductVariant/Create/_headerTitle.html.twig"
_sylius.yaml
app_admin_something_related_to_product:
driver:
name: doctrine/orm
options:
class: App\Entity\xxx
repository:
method: findByProduct
arguments: [$productId]
fields:
field1.name:
type: string
label: xxx
field2.name:
type: string
label: xxx
field3.name:
type: string
label: xxx
field4.name:
type: string
label: xxx
actions:
main:
create:
type: create
label: sylius.ui.create
options:
class: primary
icon: plus
header:
icon: cube
label: sylius.ui.type
label: app.ui.int_type
link:
route: app_admin_something_related_to_product_create
parameters:
productId: $productId
Take a look at vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Resources/config/routing/product_variant.yml - it also has $productId as a route parameter, so that is a perfect example.
Also, take a look into vendor/sylius/resource-bundle/src/Bundle/Routing/ResourceLoader.php where parameters are taken to generate index/create/update/etc routes from sylius.resource type of route.
If you use both (listed in the post) routes at the same time, and get an exception when pressing Save, that means it can't generate URL to the index route (as ResourceController::createAction redirects you to index route by default). The reason is - you should add parameters to the index route like this:
app_admin_something_related_to_product:
resource: |
alias: app.something_related_to_product
section: admin
templates: "#SyliusAdmin\\Crud"
grid: app_admin_something_related_to_product
vars:
all:
subheader: xxx
index:
icon: ~
route:
parameters:
productId: $productId
type: sylius.resource
prefix: /admin/products/{productId}
Or like this:
app_admin_something_related_to_product:
resource: |
alias: app.something_related_to_product
section: admin
templates: "#SyliusAdmin\\Crud"
grid: app_admin_something_related_to_product
vars:
route:
parameters:
productId: $productId
all:
subheader: xxx
index:
icon: ~
type: sylius.resource
prefix: /admin/products/{productId}

adding the delete fuction to orocommerce symfony datagrid

so today i would like to add the delete function for my datagrid, my datagrid is looking like this now:
datagrids:
document-grid:
source:
type: orm
query:
select:
- document.id
- document.name
- document.file
from:
- { table: LeadsBundle:document, alias: document}
columns:
id:
label: ID
frontend_type: integer
name:
label: Name
file:
label: File
sorters:
columns:
id:
data_name: document.id
name:
data_name: document.name
file:
data_name: document.file
filters:
columns:
id:
type: number
data_name: document.id
name:
type: string
data_name: document.name
file:
type: string
data_name: document.file
properties:
id: ~
update_link:
type: url
route: document_update
params:
- id
actions:
update:
type: navigate
label: Update
link: update_link
icon: edit
acl_resource: document_update
The update is completely working and now so want to add the delete function can someone help me out? I have tried it from some documentations but I didn't got it to work yet.
Delete action can appear automatically in a data-grid, but you should make an entity configurable and specify the routeName entity config option.
Otherwise, you should implement the action manually and add it in the same way as the update action.

Add custom action in Sylius resource grid

I have created a grid from a custom Resource (Newsletter), and I would like to add, on each line, a "send" button, next to the defaut "edit" and "delete" buttons.
But I don't know how to defined a custom action in the grid definition and I don't find the info in the Sylius docs...
Here is my grid def :
sylius_grid:
grids:
admin_newsletter:
driver:
name: doctrine/orm
options:
class: NewsletterBundle\Entity\Newsletter
sorting:
date: desc
fields:
titre:
type: string
label: sylius.ui.title
sortable: ~
date:
type: datetime
label: sylius.ui.date
sortable: ~
options:
format: d/m/Y
envoye:
type: twig
label: admin.ui.newsletter_envoye
sortable: ~
options:
template: NewsletterBundle:Helper:_sent.html.twig
filters:
search:
type: string
label: sylius.ui.search
options:
fields: [titre]
actions:
main:
create:
type: create
item:
update:
type: update
delete:
type: delete
# This is what I want:
send:
type: send
Any idea of how to do that ?
Thanks !
I suppose that all you need to do is add your own Action template (AppBundle/Resources/views/Grid/Action/send.html.twig),
and then configure it in the app/config/config.yml:
just like the default actions are defined here: https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/AdminBundle/Resources/config/app/config.yml#L34
sylius_grid:
templates:
action:
send: "#AppBundle/Grid/Action/send.html.twig"
Check the template path, because I am not sure of it.

Sylius : new entity grid not executing

I'm using Sylius alpha version,
i created a new entity following this docs :
sylius docs
but when i try to change a filed label in the grid or add a filed nothing changes in the create form even when i clear the cache. I think there's a lack of documentation.
app/config/grids/admin/category.yml:
sylius_grid:
grids:
app_admin_category:
driver:
name: doctrine/orm
options:
class: AppBundle\Entity\Category
fields:
name:
type: string
label: sylius.ui.name
taxon:
type: string
label: sylius.ui.taxon
actions:
main:
create:
type: create
item:
update:
type: update
delete:
type: delete
app/config/routing/admin/category.yml:
app_admin_category:
resource: |
alias: app.category
section: admin
templates: SyliusAdminBundle:Crud
redirect: update
grid: app_admin_category
vars:
all:
subheader: app.ui.category
index:
icon: 'file image outline'
type: sylius.resource

Configure custom template for Sonata Admin bundle

I have created a custom template for create action, I tried to configure it as mentioned in the documentation:
article.admin.article:
class: ArticleBundle\Admin\ArticleAdmin
arguments: [~, ArticleBundle\Entity\Article, "ArticleBundle:ArticleAdmin"]
tags:
- { name: sonata.admin, manager_type: orm, group: admin, label: Article }
calls:
- [ setTemplate, [create, "ArticleBundle:ArticleAdmin:ArticleBundle"]]
My new create.html.twig template is in directory: src\ArticleBundle\Resources\views\ArticleAdmin\ArticleBundle
When I load create page I still get the default template, not the one I configured.
What can be wrong?
In:
group: admin, label: Article
you are missing double quotes. Should be:
group: "admin", label: "Article"
The call for setTemplate should be:
calls:
- [ setTemplate, [create, "ArticleBundle:ArticleAdmin:ArticleBundle/create.html.twig"]]
See Sonata Admin templates reference.

Resources