Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Last active January 11, 2016 09:09
Show Gist options
  • Save webdevilopers/26f0ffd9cccaf9403cdf to your computer and use it in GitHub Desktop.
Save webdevilopers/26f0ffd9cccaf9403cdf to your computer and use it in GitHub Desktop.
Sonata Admin Role Handler isGranted usage in parent Admin Class
<?php
class BundleAdmin extends Admin
{
protected $parentAssociationMapping = 'contract';
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('date', 'date');
if (!$this->isChild()) {
$listMapper->add('contract');
}
}
}
sonata_admin:
security:
handler: sonata.admin.security.handler.role
<?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'),
))
)
;
}
}
}
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
@webdevilopers
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment