public function bulkDeleteAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'update'));
        $form = $this->formFactory->deletePolicies(
            new PoliciesDeleteData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (PoliciesDeleteData $data) use ($role) {
                $roleDraft = $this->roleService->createRoleDraft($role);

                foreach ($data->getPolicies() as $policyId => $selected) {
                    foreach ($roleDraft->getPolicies() as $policyDraft) {
                        if ($policyDraft->originalId === $policyId) {
                            $this->roleService->removePolicyByRoleDraft($roleDraft, $policyDraft);
                        }
                    }
                }

                $this->roleService->publishRoleDraft($roleDraft);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Policies in role '%role%' removed.") */
                        'policy.delete.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $role->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('ezplatform.role.view', [
            'roleId' => $role->id,
        ]));
    }
public function bulkDeleteAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'update'));
        $form = $this->formFactory->deletePolicies(
            new PoliciesDeleteData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (PoliciesDeleteData $data) use ($role) {
                $roleDraft = $this->roleService->createRoleDraft($role);

                foreach ($data->getPolicies() as $policyId => $selected) {
                    foreach ($roleDraft->getPolicies() as $policyDraft) {
                        if ($policyDraft->originalId === $policyId) {
                            $this->roleService->removePolicyByRoleDraft($roleDraft, $policyDraft);
                        }
                    }
                }

                $this->roleService->publishRoleDraft($roleDraft);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Policies in role '%role%' removed.") */
                        'policy.delete.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $role->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('ezplatform.role.view', [
            'roleId' => $role->id,
        ]));
    }
public function bulkDeleteAction ( Request $ request , Role $ role ) : Response { $ this -> denyAccessUnlessGranted ( new Attribute ( 'role' , 'update' ) ) ; $ form = $ this -> formFactory -> deletePolicies ( new PoliciesDeleteData ( ) ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) ) { $ result = $ this -> submitHandler -> handle ( $ form , function ( PoliciesDeleteData $ data ) use ( $ role ) { $ roleDraft = $ this -> roleService -> createRoleDraft ( $ role ) ; foreach ( $ data -> getPolicies ( ) as $ policyId => $ selected ) { foreach ( $ roleDraft -> getPolicies ( ) as $ policyDraft ) { if ( $ policyDraft -> originalId === $ policyId ) { $ this -> roleService -> removePolicyByRoleDraft ( $ roleDraft , $ policyDraft ) ; } } } $ this -> roleService -> publishRoleDraft ( $ roleDraft ) ; $ this -> notificationHandler -> success ( $ this -> translator -> trans ( /** @Desc("Policies in role '%role%' removed.") */ 'policy.delete.success' , [ '%role%' => $ role -> identifier ] , 'role' ) ) ; return new RedirectResponse ( $ this -> generateUrl ( 'ezplatform.role.view' , [ 'roleId' => $ role -> id , ] ) ) ; } ) ; if ( $ result instanceof Response ) { return $ result ; } } return $ this -> redirect ( $ this -> generateUrl ( 'ezplatform.role.view' , [ 'roleId' => $ role -> id , ] ) ) ; }
Handles removing policies based on submitted form.

@param \Symfony\Component\HttpFoundation\Request $request
@param \eZ\Publish\API\Repository\Values\User\Role $role

@return \Symfony\Component\HttpFoundation\Response

@throws \Symfony\Component\Translation\Exception\InvalidArgumentException
@throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
@throws \InvalidArgumentException
Handles removing policies based on submitted form .