Last active
January 11, 2016 09:09
-
-
Save webdevilopers/26f0ffd9cccaf9403cdf to your computer and use it in GitHub Desktop.
Sonata Admin Role Handler isGranted usage in parent Admin Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BundleAdmin extends Admin | |
{ | |
protected $parentAssociationMapping = 'contract'; | |
protected function configureListFields(ListMapper $listMapper) | |
{ | |
$listMapper | |
->add('date', 'date'); | |
if (!$this->isChild()) { | |
$listMapper->add('contract'); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sonata_admin: | |
security: | |
handler: sonata.admin.security.handler.role |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Sonata\AdminBundle\Datagrid\ListMapper; | |
use Symfony\Component\Security\Core\SecurityContextInterface; | |
class ContractAdmin extends Admin | |
{ | |
/** | |
* Security Context | |
* @var \Symfony\Component\Security\Core\SecurityContextInterface | |
*/ | |
protected $securityContext; | |
public function setSecurityContext(SecurityContextInterface $securityContext) | |
{ | |
$this->securityContext = $securityContext; | |
} | |
protected function configureListFields(ListMapper $listMapper) | |
{ | |
$listMapper | |
->add('updatedAt', 'datetime'); | |
//if ($this->securityContext->isGranted('ROLE_SONATA_ADMIN_BUNDLE_LIST')) { | |
if ($this->isGranted('ROLE_SONATA_ADMIN_BUNDLE_LIST')) { | |
$listMapper | |
->add('_action', 'actions', array( | |
'actions' => array( | |
'show' => array(), | |
'edit' => array(), | |
'show_bundles' => array('template' => 'AcmeContractBundle:ContractAdmin:list__bundles.html.twig'), | |
)) | |
) | |
; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security: | |
encoders: | |
FOS\UserBundle\Model\UserInterface: sha512 | |
role_hierarchy: | |
ROLE_ADMIN: | |
- ROLE_SONATA_ADMIN_CONTRACT_LIST | |
- ROLE_SONATA_ADMIN_BUNDLE_LIST | |
ROLE_SUPER_ADMIN: | |
- ROLE_ADMIN | |
access_decision_manager: | |
strategy: unanimous |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related issue:
sonata-project/SonataAdminBundle#2605