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.
Related
I have admin like "User Admin" and one child admin like "Document Admin""
admin.users:
class: App\Admin\UserAdmin
arguments: [~, App\Entity\User, SonataAdminBundle:CRUD]
calls:
- [addChild, ['#admin.documents'] ]
tags:
- {name: sonata.admin, manager_type: orm, label: Users}
public: true
admin.documents:
class: App\Admin\DocumentsAdmin
arguments: [~, App\Entity\Document, ~]
calls:
- [setParentAssociationMapping, ['user']]
- [setTranslationDomain, ['admin']]
tags:
- {name: sonata.admin, manager_type: orm, label: Documents}
public: true
And i try to remove create and delete route
App\Admin\DocumentAdmin
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->remove('delete');
$collection->remove('create');
}
But when i open this admin (/admin/app/user/1/document/list), i receive error:
An exception has been thrown during the rendering of a template
("Unable to generate a URL for the named route
"admin_app_user_document_create" as such route does not exist.").
Not working, but should be. I want to see child admin wit users documents without add and create buttons.
But when i open document admin directly ( /admin/app/document/list ) - everything is ok! I see list without add and edit and delete button.
How to remove routes in DocumentAdmin for both situation ?
Symfony 4 / Sonata Admin 3.35
You only removed the create and delete links. You need to remove the link to list the entity too. I guess this is what you need? Add this line too.
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->remove('delete');
$collection->remove('create');
$collection->remove('list');
}
You can see list documents because you did not remove the list action from route collection.
Just do cache:clear it take time to regenerate routes
How can I change the labels in the left menu of my Sonata Admin installation?
I would like to change (and understand how they are generated):
The "admin" text
The "PostCategory" label (and change it to something more "WordPress-ish" :) like "Post Categories")
These labels are defined in the tags property in the service definition of your admin page, in the config file of the admin section. See documentation here.
Example in a admin-services.yml file:
services:
app.admin.category:
class: AppBundle\Admin\CategoryAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "My Admin Group", label: "Post Categories" }
arguments:
- ~
- AppBundle\Entity\Category
- ~
calls:
- [ setTranslationDomain, [AppBundle]]
The group tag corresponds to your admin label, and the label one to your PostCategory.
I guess you didn't specify these tags, and admin is the default group name, and PostCategory the name of your class.
EDIT:
The label and the group option are translation keys. You specify the translation domain under the calls tag, with setTranslationDomain, and the default catalog is messages. See documentation on translation here.
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.
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
I've implemented the SonataAdmin and SonataUserBundle into my project.
With this I've created the Application\Sonata\UserBundle which has a User entity. This entity uses xml-mapping for Doctrine. I'm wondering if it's possible to change this configuration to annotations as I'm using annotations in the rest of my project.
Thx.
sonata.user.admin.user:
class: %sonata.user.admin.user.class%
tags:
- { name: sonata.admin, manager_type: orm, group: Usuarios, label: Usuarios }
arguments: [null, %sonata.user.admin.user.entity%, SonataAdminBundle:CRUD]
calls:
- [ setUserManager, [fos_user.user_manager]]
where sonata.user.admin.user.class and .entity are values set in your config file.
You should probably change your fos_user.user_manager also but i don't know what you use...