I use Easyadmin bundle for the administrative part of the web-application and I use configuration like this:
easy_admin:
entities:
Payment:
class: App\Entity\Payment
controller: App\Controller\CompanyController
label: 'payments'
list:
item_permission: ['ROLE_ADMIN','ROLE_COMPANY_OWNER','ROLE_COMPANY_ACCOUNTANT']
actions: ['show', '-delete', '-edit', '-new']
collapse_actions: true
title: 'Payments'
filters:
- { property: 'id', label: 'id' }
- { property: 'type', label: 'type' }
- { property: 'user', label: 'user' }
...
The problem is about I can't set filter via entity relation, like { property: 'user.company', label: 'company' }, it throws exception that property does not exist or misconfigurated. Does anybody have any idea how to solve this?
you can use Static Filters (dql_filter Option)
The dql_filter option lets you define the conditions passed to the WHERE clause of the Doctrine query used to get the entities displayed in the list and search views.
for exemple
easy_admin:
entities:
VipCustomers:
class: App\Entity\User
list:
dql_filter: 'entity.budget > 100000'
RegularCustomers:
class: App\Entity\User
list:
dql_filter: 'entity.budget <= 100000'
and in your case i think you can do something like this.
easy_admin:
entities:
Payment:
class: App\Entity\Payment
controller: App\Controller\CompanyController
label: 'payments'
list:
item_permission: ['ROLE_ADMIN','ROLE_COMPANY_OWNER','ROLE_COMPANY_ACCOUNTANT']
actions: ['show', '-delete', '-edit', '-new']
collapse_actions: true
title: 'Payments'
dql_filter: "user.company"
Related
This what happens when I put translation:
# translations/messages.en.yaml
Post: Posts
easy_admin:
entities:
Post:
class: App\Entity\Post
list:
fields:
- { property: 'title', label: 'post.title' }
- { property: 'post', label: 'post.content' }
In the side menu I need it as Posts and in the create page as Create post. Can't find how to translate these.
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.
Context : I want my users to be able to moderate my themes. I created a role moderator, and added a "moderation" (array) field to my user. Therefore, I can give rights to a specific user to one or more Themes.
I'm creating a Back Office to manage users using EasyAdmin & Symfony4.
I want to have a multiple select field displaying my available theme to give rights to users.
Here is my current configuration of easy admin :
User:
class: App\Entity\User
disabled_actions: ['new']
edit:
fields:
- username
- email
- { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_USER': 'ROLE_USER', 'ROLE_MODERATOR': 'ROLE_MODERATOR', 'ROLE_ADMIN': 'ROLE_ADMIN' } } }
- { property: 'moderate', type: 'entity', type_options: { class: 'App\Entity\Theme', multiple: true } }
Things are going pretty well, since I'm able to edit my user, give him a role, and give him sites to moderate.
The issue :
The current state of my "moderate" array is not displayed. The select doesn't have the current value displayed when showing up.
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.
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.