src/Controller/CRUDController.php
public function aclAction($id = null)
    {
        $request = $this->getRequest();

        if (!$this->admin->isAclEnabled()) {
            throw $this->createNotFoundException('ACL are not enabled for this admin');
        }

        $id = $request->get($this->admin->getIdParameter());

        $object = $this->admin->getObject($id);

        if (!$object) {
            throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
        }

        $this->admin->checkAccess('acl', $object);

        $this->admin->setSubject($object);
        $aclUsers = $this->getAclUsers();
        $aclRoles = $this->getAclRoles();

        $adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
        $adminObjectAclData = new AdminObjectAclData(
            $this->admin,
            $object,
            $aclUsers,
            $adminObjectAclManipulator->getMaskBuilderClass(),
            $aclRoles
        );

        $aclUsersForm = $adminObjectAclManipulator->createAclUsersForm($adminObjectAclData);
        $aclRolesForm = $adminObjectAclManipulator->createAclRolesForm($adminObjectAclData);

        if ('POST' === $request->getMethod()) {
            if ($request->request->has(AdminObjectAclManipulator::ACL_USERS_FORM_NAME)) {
                $form = $aclUsersForm;
                $updateMethod = 'updateAclUsers';
            } elseif ($request->request->has(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME)) {
                $form = $aclRolesForm;
                $updateMethod = 'updateAclRoles';
            }

            if (isset($form)) {
                $form->handleRequest($request);

                if ($form->isValid()) {
                    $adminObjectAclManipulator->$updateMethod($adminObjectAclData);
                    $this->addFlash(
                        'sonata_flash_success',
                        $this->trans('flash_acl_edit_success', [], 'SonataAdminBundle')
                    );

                    return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
                }
            }
        }

        // NEXT_MAJOR: Remove this line and use commented line below it instead
        $template = $this->admin->getTemplate('acl');
        // $template = $this->templateRegistry->getTemplate('acl');

        return $this->renderWithExtraParams($template, [
            'action' => 'acl',
            'permissions' => $adminObjectAclData->getUserPermissions(),
            'object' => $object,
            'users' => $aclUsers,
            'roles' => $aclRoles,
            'aclUsersForm' => $aclUsersForm->createView(),
            'aclRolesForm' => $aclRolesForm->createView(),
        ], null);
    }
public function aclAction($id = null)
    {
        $request = $this->getRequest();

        if (!$this->admin->isAclEnabled()) {
            throw $this->createNotFoundException('ACL are not enabled for this admin');
        }

        $id = $request->get($this->admin->getIdParameter());

        $object = $this->admin->getObject($id);

        if (!$object) {
            throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
        }

        $this->admin->checkAccess('acl', $object);

        $this->admin->setSubject($object);
        $aclUsers = $this->getAclUsers();
        $aclRoles = $this->getAclRoles();

        $adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
        $adminObjectAclData = new AdminObjectAclData(
            $this->admin,
            $object,
            $aclUsers,
            $adminObjectAclManipulator->getMaskBuilderClass(),
            $aclRoles
        );

        $aclUsersForm = $adminObjectAclManipulator->createAclUsersForm($adminObjectAclData);
        $aclRolesForm = $adminObjectAclManipulator->createAclRolesForm($adminObjectAclData);

        if ('POST' === $request->getMethod()) {
            if ($request->request->has(AdminObjectAclManipulator::ACL_USERS_FORM_NAME)) {
                $form = $aclUsersForm;
                $updateMethod = 'updateAclUsers';
            } elseif ($request->request->has(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME)) {
                $form = $aclRolesForm;
                $updateMethod = 'updateAclRoles';
            }

            if (isset($form)) {
                $form->handleRequest($request);

                if ($form->isValid()) {
                    $adminObjectAclManipulator->$updateMethod($adminObjectAclData);
                    $this->addFlash(
                        'sonata_flash_success',
                        $this->trans('flash_acl_edit_success', [], 'SonataAdminBundle')
                    );

                    return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
                }
            }
        }

        // NEXT_MAJOR: Remove this line and use commented line below it instead
        $template = $this->admin->getTemplate('acl');
        // $template = $this->templateRegistry->getTemplate('acl');

        return $this->renderWithExtraParams($template, [
            'action' => 'acl',
            'permissions' => $adminObjectAclData->getUserPermissions(),
            'object' => $object,
            'users' => $aclUsers,
            'roles' => $aclRoles,
            'aclUsersForm' => $aclUsersForm->createView(),
            'aclRolesForm' => $aclRolesForm->createView(),
        ], null);
    }
public function aclAction ( $ id = null ) { $ request = $ this -> getRequest ( ) ; if ( ! $ this -> admin -> isAclEnabled ( ) ) { throw $ this -> createNotFoundException ( 'ACL are not enabled for this admin' ) ; } $ id = $ request -> get ( $ this -> admin -> getIdParameter ( ) ) ; $ object = $ this -> admin -> getObject ( $ id ) ; if ( ! $ object ) { throw $ this -> createNotFoundException ( sprintf ( 'unable to find the object with id: %s' , $ id ) ) ; } $ this -> admin -> checkAccess ( 'acl' , $ object ) ; $ this -> admin -> setSubject ( $ object ) ; $ aclUsers = $ this -> getAclUsers ( ) ; $ aclRoles = $ this -> getAclRoles ( ) ; $ adminObjectAclManipulator = $ this -> get ( 'sonata.admin.object.manipulator.acl.admin' ) ; $ adminObjectAclData = new AdminObjectAclData ( $ this -> admin , $ object , $ aclUsers , $ adminObjectAclManipulator -> getMaskBuilderClass ( ) , $ aclRoles ) ; $ aclUsersForm = $ adminObjectAclManipulator -> createAclUsersForm ( $ adminObjectAclData ) ; $ aclRolesForm = $ adminObjectAclManipulator -> createAclRolesForm ( $ adminObjectAclData ) ; if ( 'POST' === $ request -> getMethod ( ) ) { if ( $ request -> request -> has ( AdminObjectAclManipulator :: ACL_USERS_FORM_NAME ) ) { $ form = $ aclUsersForm ; $ updateMethod = 'updateAclUsers' ; } elseif ( $ request -> request -> has ( AdminObjectAclManipulator :: ACL_ROLES_FORM_NAME ) ) { $ form = $ aclRolesForm ; $ updateMethod = 'updateAclRoles' ; } if ( isset ( $ form ) ) { $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ adminObjectAclManipulator -> $ updateMethod ( $ adminObjectAclData ) ; $ this -> addFlash ( 'sonata_flash_success' , $ this -> trans ( 'flash_acl_edit_success' , [ ] , 'SonataAdminBundle' ) ) ; return new RedirectResponse ( $ this -> admin -> generateObjectUrl ( 'acl' , $ object ) ) ; } } } // NEXT_MAJOR: Remove this line and use commented line below it instead $ template = $ this -> admin -> getTemplate ( 'acl' ) ; // $template = $this->templateRegistry->getTemplate('acl'); return $ this -> renderWithExtraParams ( $ template , [ 'action' => 'acl' , 'permissions' => $ adminObjectAclData -> getUserPermissions ( ) , 'object' => $ object , 'users' => $ aclUsers , 'roles' => $ aclRoles , 'aclUsersForm' => $ aclUsersForm -> createView ( ) , 'aclRolesForm' => $ aclRolesForm -> createView ( ) , ] , null ) ; }
Returns the Response object associated to the acl action.

@param int|string|null $id

@throws AccessDeniedException If access is not granted
@throws NotFoundHttpException If the object does not exist or the ACL is not enabled

@return Response|RedirectResponse
Returns the Response object associated to the acl action .