I'm trying to customize my dashboard of Sonata but although I can change the layout, I can't make the controller to be the one I want (and with that pass some other values). So sonata always loads the default on the CoreController and not the one that I want. Can you tell me what I have to do for changing the controller for the one I want?
This is a part of my config.yml:
sonata_admin:
title_logo: bundles/ebuigui/images/brand.png
templates:
dashboard: EBUIBackendBundle:CRUD:adminView.html.twig
list: EBUIBackendBundle:CRUD:list.html.twig
edit: EBUIBackendBundle:CRUD:create.html.twig
dashboard:
blocks:
# display a dashboard block
- { position: left, type: sonata.admin.block.admin_list }
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
it's better that you use eventListener to modif the logic of Sonata CoreController. If you want to override the core controller you can reffer to a question asked before
Related
I am having a weird situation which has halted my progress for the second day now and I am almost going bald from pulling my hair on this. I have a custom block on the sonata admin dashboard which is not being found when I try to load the page.
I have gone over the configuration a couple of times and maybe I am missing something which an extra pair of eyes may be able to spot which is why I am posting this question here.
I have built my block as below and saved it under src\AppBundle\Block\NumbersBlockService.php
namespace AppBundle\Block;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Doctrine\ORM\Query\ResultSetMapping;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use DoctrineExtensions\Query\Mysql;
class NumbersBlockService extends BaseBlockService
{
......
}
Then defined my service in the service.yml file as below:
sonata.block.service.topnumbers:
class: AppBundle\Block\NumbersBlockService
arguments:
- sonata.block.service.topnumbers
- "#templating"
- "#doctrine.orm.entity_manager"
- "#security.token_storage"
tags:
- { name: sonata.block }
My config.yml file includes the block like this
sonata_block:
default_contexts: [cms]
blocks:
sonata.user.block.menu: # used to display the menu in profile pages
sonata.user.block.account: # used to display menu option (login option)
sonata.block.service.text: # used to if you plan to use Sonata user routes
sonata.block.service.topnumbers:
and finally, I position the block on top with the line below
sonata_admin:
dashboard:
blocks:
- { position: top, type: sonata.block.service.topnumbers, class: col-md-12}
I have checked the tutorial on creating a custom block here https://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html and everything seems to check out but I still get the following error below:
An exception has been thrown during the rendering of a template ("The block type "sonata.block.service.topnumbers" does not exist") in SonataAdminBundle:Core:dashboard.html.twig at line 60.
Someone please help put me out of my misery. Thanks in advance
I try to override layout template in Sonata Admin. I did all steps founded in official documentation, but my changes don`t work.
I did:
Copied from vendor appropriate template (standard_layout.html.twig) to app/Resources/SonataAdminBundle/views/. I will check if I override here template my changes applied to all of Admins in project (I want have this change only in one Admin)
In next step I created new file in my Bundle (Name/InfoBundle/Resources/views/JobOffer) and add there my custom template: findCandidate.html.twig. Below is content of this file:
https://gist.github.com/anonymous/5f4780a1ae8d7329cd91
Added to bundle service:
name_info.admin.offers:
class: Name\InfoBundle\Admin\JobOfferAdmin
tags:
- {name: sonata.admin, manager_type: orm, group: Info, label: Job offers}
arguments: [~, Name\Info\Entity\JobOffer, NameInfoBundle:JobOffer]
calls:
- [ setTemplate, [findCandidate, NameInfoBundle:JobOffer:findCandidate.html.twig]]
After that my changes are not applied. So probably I made mistake in services or maybe I have to call this template also in controller? I am not sure where I make mistake. Could anyone help me?
Probably you mistyped a template placeholder in setTemplate function.
Try to set it like:
calls:
- [setTemplate, [layout, NameInfoBundle:JobOffer:findCandidate.html.twig]]
It will change a standard_layout only for the selected admin.
I'm working on a web project using Symfony2 , and i used Sonata Admin for the admin Panel , every thing works fine but what i want to do is ,on the dashboard menus of sonata Admin , i need to show hide some menus depend on the admin ROLE , so did any one do this before or know how to do it ?
i tryed to use the config of the roles but when i'm connecting with a ROlE diffrent of ROLE_SONATA_ADMIN the top menu dont show up ,
- { path: ^/admin, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN,ROLE_ADMIN_NEWS] }
thanks
i found the solution for this i need just to define the groups on the config.yml Like this
dashboard:
groups:
Content:
label: Content
items:
- sonata.admin.pages
- sonata.admin.menus
roles: [ ROLE_ADMIN_CONTENT, ROLE_SUPER_ADMIN ]
I'd like to render the links to user management and ACL editing on my SonataAdmin Dashboard. What do I need to add to sonata_block section? Also, what are these 'cms' and 'admin' contexts?
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
# Your other blocks
sonata.user.block.menu: ~ # used to display the menu in profile pages
sonata.user.block.account: ~ # used to display menu option (login option)
sonata.block.service.text: ~
sonata.block.service.rss: ~
sonata.block.service.imagesize:
contexts: [admin]
groups:
admin.group.content:
label: My Label
label_catalogue: SonataAdminBundle
items:
- sonata.admin.????
Please note, the cms context will be renamed into sonata_page_bundle to be more appropriate.
Each block can be defined in a specific context (ie, an admin related block does not need to be added as a cms block).
So if we set a context to a block, the default value will not be applied and so the block will be not listed in the SonataPageBundle or any other bundles using this context.
Now, if you want to add content into the dashboard, you have some options:
- overwrite the dashboard template so you can fine tune the overall layout and add link to the user management.
- create a block and add it to the block configuration of the sonata_admin section.
You can create a new block by following the BlockBundle tutorial available at: http://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html
This is a weird problem I am facing. The Sonata admin bundle logo and the title are displayed on 2 different lines..
The following are the contents of my config file.
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.action:
sonata.block.service.rss:
sonata_admin:
title: MyTitle
Any ideas?
try your own logo
sonata_admin:
title: MyTitle
title_logo: /bundles/yourbundle/images/logo.png