i'm newbie of sonata,
i have a ContentTestAdmin with entity etc, that can only contains 4 record
- record 1
- record 2
- record 3
- record 4
i already disabled create and delete function
public function configureRoutes(RouteCollection $collection)
{
$collection->remove('create')->remove('delete');
}
but i need to change link on dashboard and on the left menu:
actually i put on my service.yml
admin.comuni:
class: AppBundle\Admin\ContentTestAdmin
arguments: [~, AppBundle\Entity\ContentTest, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Content Test, group: Main Section }
and i see on dashboard the box with title "Content" and inside the "Content Test" with link to the list
i would erase this part and see like
Content test
- record 1 title > with link to 1/edit
- record 2 title > with link to 2/edit
- record 3 title > with link to 3/edit
- record 4 title > with link to 4/edit
same issue for the left menu, a folder named Content test with 4 link inside
is possible? thank you
You should be configuring your admin menu in your app/config.yml.
Here is an example :
sonata_admin:
dashboard:
groups:
content_test:
label: Content
icon: '<i class="fa fa-address-card"></i>'
items:
- route: 'route_to_record1'
route_params: { id: 1 } #id of record 1
label: Record 1
- route: 'route_to_record_2'
route_params: { id: 2 }
label: Record 2
To find out the route to a record execute the command
app/console (bin/console on sf3) debug:router
This will show you all the routes existing in your app just find the route sonata admin generated for your ContentAdmin for show or edit or whatever you need( ex: admin_content_test_show).then just fill route_params with the id of the desired record.
(you can use that to point to any route in your app and prefill any parameters of that route)
Hope you find this helpful
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
When creating a page, pagination takes a very long time. I want to delete it or override it. Tell me who faced I want to remove these things
To remove only the Twig view (no impact on performance, it's just visual) :
you can define a custom Pager using this :
# app/config/your_sonata_services_config.yml
services:
app.admin.post:
class: AppBundle\Admin\PostAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Content", label: "Post", pager_type: "simple" }
arguments:
- ~
- AppBundle\Entity\Post
- ~
public: true
With tag pager_type: simple, the view SonataAdminBundle:Pager:simple_pager_results.html.twig will be called.
source : https://symfony.com/doc/master/bundles/SonataAdminBundle/cookbook/recipe_improve_performance_large_datasets.html
To disable COUNT(*) of rows and improve performance :
You can have a look here https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/297, you have to :
extend the default SonataPager with your own class that overrides computeNbResult()
extends the default SonataProxyQuery with your own class that overrides getFixedQueryBuilder()
extend the default SonataDatagridBuilder with your own class that overrides getBaseDatagrid()
Reference those in your services
i defined custom entity and defined field_ui_base_route in annotation to activate field ui .
the problem is the field ui tabs don't appear on base route page but only after visiting them manually in address bar .
field_ui_base_route is portal_admin.office_overview
portal_admin.office_overview:
path: '/admin/portal/org/office'
defaults:
_title: 'Portal organization'
_entity_list: 'portal_office'
requirements:
_permission: 'administer portal'
in links.task.yml i have default task :
portal_admin.office_overview:
route_name: portal_admin.office_overview
title: Overview
base_route: portal_admin.office_overview
when i manually visit /admin/portal/org/office/fields i do see all tabs .
but when clicking main tab Overview the tabs don't appear .
strangely when i do striped down example not related to entities and field ui the tabs do work :
mod1.page5:
title: 'Main'
route_name: mod1.page5
base_route: mod1.page5
mod1.page51:
title: 'sub1'
route_name: mod1.page51
base_route: mod1.page5
mod1.page52:
title: 'sub2'
route_name: mod1.page52
base_route: mod1.page5
problem fixed .
i defined the entity routes to be generated automatically using AdminHtmlRouteProvider
but also defined the path for entity.portal_office.collection manually as route portal_admin.office_overview
so this is why the route portal_admin.office_overview has local task while the route entity.portal_office.collection did not and the tabs did not appear because the route entity.portal_office.collection prevailed over portal_admin.office_overview .
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 need to clean the admin side so it fits to the need of my client.
I'm using NewsBundle from Sonata, i actually don't need to use comments so i'd like to remove it from the admin side. At least from the menu. Is there a way to disable it in the config? I have not find any hints in the doc about this.
Here the specific area where i would like to not see it anymore :
By the way, the menu might be generated by KnpMenu
To customize the groups shown in the dashsboard and side menu, you need to edit your app/config/config.yml:
sonata_admin:
dashboard:
...
groups:
sonata_blog:
label: sonata_content
label_catalogue: SonataNewsBundle
icon: '<i class="fa fa-th"></i>'
items:
# - sonata.news.admin.comment
- sonata.news.admin.post
sonata.admin.group.classification:
label: sonata_classification
label_catalogue: SonataClassificationBundle
icon: '<i class="fa fa-sitemap"></i>'
items:
- sonata.classification.admin.category
- sonata.classification.admin.tag
- sonata.classification.admin.collection
...