public function editPolicyAction(Request $request, $roleId, $policyId = null) { $role = $this->roleService->loadRole($roleId); try { $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId); } catch (NotFoundException $e) { // The draft doesn't exist, let's create one $roleDraft = $this->roleService->createRoleDraft($role); } $policy = new PolicyDraft(['innerPolicy' => new Policy()]); if ($policyId) { foreach ($roleDraft->getPolicies() as $policy) { if ($policy->originalId == $policyId) { goto buildFormData; } } throw new BadRequestHttpException($this->translator->trans('role.error.policy_not_found', ['%policyId%' => $policyId, '%roleId%' => $roleId], 'role')); } buildFormData: $limitationTypes = $policy->module ? $this->roleService->getLimitationTypesByModuleFunction($policy->module, $policy->function) : []; $policyData = (new PolicyMapper())->mapToFormData($policy, ['roleDraft' => $roleDraft, 'initialRole' => $role, 'availableLimitationTypes' => $limitationTypes]); $actionUrl = $this->generateUrl('admin_policyEdit', ['roleId' => $roleId, 'policyId' => $policyId]); $form = $this->createForm('ezrepoforms_policy_edit', $policyData); $form->handleRequest($request); if ($form->isValid()) { $this->policyActionDispatcher->dispatchFormAction($form, $policyData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null); if ($response = $this->policyActionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } return $this->render('eZPlatformUIBundle:Role:edit_policy.html.twig', ['form' => $form->createView(), 'actionUrl' => $actionUrl, 'policy' => $policyData]); }
/** * Returns the LimitationType's assigned to a given module/function. * * Typically used for: * - Internal validation limitation value use on Policies * - Role admin gui for editing policy limitations incl list limitation options via valueSchema() * * @param string $module Legacy name of "controller", it's a unique identifier like "content" * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read" * * @return \eZ\Publish\SPI\Limitation\Type[] * * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping * refers to a non existing identifier. */ public function getLimitationTypesByModuleFunction($module, $function) { return $this->service->getLimitationTypesByModuleFunction($module, $function); }