I need to create a new ROLE called STATUS to appear in ROLE MANAGER of User CRUD like the image at link see image, this roles is based on a custom route defined in the admin class, and a custom controller.
I've resolved modifying the config file adding a information
parameter with the default list of ROLE, but this will apply to all admin class defined in the service, and I don't want that, I want define the ROLE for a specific admin class, and also that can appear in the role manager in order to be assigned a user.
Any suggestion is welcome
Thanks for help!
These are my configurations:
config.yml
#SONATAADMINBUNDLE
sonata_admin:
security:
handler: sonata.admin.security.handler.role
information:
EDIT: EDIT
LIST: LIST
CREATE: CREATE
VIEW: VIEW
DELETE: DELETE
EXPORT: EXPORT
OPERATOR: OPERATOR
MASTER: MASTER
STATUS: STATUS
AdminClass
//..
use Sonata\AdminBundle\Route\RouteCollection;
class SolicitudMantenimientoAdmin extends Admin
{
//...
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('status',$this->getRouterIdParameter().'/status');
}
}
Service
<service id="sonata.admin.solicitudmantenimiento" class="Minsal\SimBundle\Admin\SolicitudMantenimientoAdmin">
<tag name="sonata.admin" manager_type="orm" group="Solicitud" label="Solicitud Mantenimiento" />
<argument />
<argument>Minsal\SimBundle\Entity\SolicitudMantenimiento</argument>
<argument>MinsalSimBundle:SolicitudMantenimiento</argument>
</service>
Controller
use Sonata\AdminBundle\Controller\CRUDController;
class SolicitudMantenimientoController extends CRUDController {
//..
public function statusAction() {
//... code here
return new Response('<html><body>Test</body></html>');
}
Finally I solved the problem, I read the documentation deeper (Role Handler), I made the next changes in the follow file:
security.yml
I added a new role in the security file, in the role_hierarchy section like the follow:
security:
role_hierarchy:
ROLE_SONATA_SOLICITUDMANTENIMIENTO:
- ROLE_SONATA_ADMIN_SOLICITUDMANTENIMIENTO_STATUS
When I added the new role, it appeared in the ROLE MANAGER of User CRUD, like the image at the link see image
and it works!!!...