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
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'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 ]
First I am new in Symfony2, I develop a project by using Symfony2 with SonataAdminBundle, everything is well but I don't know how to add a custom link in top menu without entity.
You need to override the standard_layout.html.twig by creating a custom admin bundle and place that file in exact the same folder structure. If you open up the original standard_layout.html.twig you can see that it has following block in it {% block top_bar_before_nav %} {% endblock %}. That's the one you want to put your own menu item in. Here is some more info about templating the SonataAdminBundle.
You can configure the config.yml
sonata_admin:
templates:
user_block: YOURBUNDLE:<optional Directory>:Twig-template
That's for sonata admin bundle :( dev-master. Kind of 2.2.x
The template is warpped by an ul-tag, so use li's:
<li>First User message</li>
A helpful console-command is
php app/console config:debug sonata_admin
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
Anyone could tell me is it possible to create in Symfony2 next:
One main Bundle: functionality, layout, templates;
Many other Bundles: additional functionality, extending templates from main Bundle;
Tried to draw an example of idea https://www.dropbox.com/s/sv15wcxhdvamu9u/sym.png
More about idea: for example we have one layout.html.twig where we have 3 blocks. in each block we have some content from main Bundle and some special tag/mark/(controller call) - it will trigger all other bundles, and if any bundle has some content for that tag/mark/(controller call) it will return the result (e.g. block with buttons "toolbar", we have few buttons from main Bundle, and few buttons from other Bundles).
Is it possible?