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 ]
Related
I am trying to create a custom admin page in drupal 8 admin
i have create a custom module name custom_admin also I have added the below code in
"custom_admin.routing.xml"
custom_admin.contactformlisting:
path: '/admin/structure/contactformlisting'
defaults:
_content:
'\Drupal\custom_admin\Controller\AdminController::contactformlisting'
_title: 'Contact Form Listing'
requirements:
_permission: 'administer contact forms listing'
_access: 'TRUE'
custom_admin_permissions.yml
administer contact forms listing:
title: 'Administer contact forms listing'
in custom_admin.links,menu.yml
custom_admin.contactformlisting:
title: Contact Form Data Listing
description: 'This is a contact form listing page link`enter code here`'
parent: system.admin_structure
route_name: custom_admin.contactformlisting
But still revceving Page not Found can anybody help me in these
Not sure if it's just a typo above, but the file "custom_admin.routing.xml" should be custom_admin.routing.yml* (yml instead of xml). The permissions yml needs to be module_name.permissions.yml - you have module_name_permissions.yml (underscore instead of period).
I also notice some spacing issues in the routing file for _access:(again not sure if just a typo here), but yml format is very specific. They need to all be indented 2 spaces.
If it's still not working, I would suggest removing the _access property altogether from the routing yml and set _permission: TRUE temporarily, just to remove any other variables that could be interfering.
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 building a web application using symfony2. I have different types of users with different roles; ROLE_STUDENT and ROLE_TEACHER, those two user can access a course's details; if the user is a teacher, a button edit is shown and if it's the student then a button subscribe will be shown, and actually this is not secure because it just hides the path to the controllers action, if the student types in the address bar /course/2/edit the edit action would be executed so I had to secure the action using #security annotation:
This is what I have done so far:
/**
* #Security("has_role('ROLE_TEACHER')")
*/ public function editAction()
{}
and in twig :
{% if is_granted('ROLE_TEACHER') %}
edit
{% elseif is_granted('ROLE_STUDENT')%}
subscribe
.
The problem is that I have a lot of accessible content to both users and I think there is a better solution to this instead of copy/past the same code all over. I'm new to Symfony 2, please bear with me.
There are multiple ways to achieve this but what you are doing is not wrong.
One way to achieve this is to set ROLE for the ROUTES so that ROLE_STUDENT roles can only access URLs that will be something like this website.com/students and ROLE_TEACHER can only access website.com/teachers
access_control:
- { path: ^/student/, roles: ROLE_STUDENT }
- { path: ^/teamleader/, roles: ROLE_TEACHER }
You can then set the edit route only for teachers like website.com/teachers/course/2/edit this way no edit route is going to be available for ROLE_STUDENT and they will get 404 error or access denied error if they try to access teacher route. You can do the same for the subscribe feature.
Like I said there are more ways to achieve this and this is one of them.
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
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