/** * @param RZ\Roadiz\Core\Entities\User $user * @param RZ\Roadiz\Core\Entities\Role $role * * @return \Symfony\Component\Form\Form */ private function buildRemoveRoleForm(User $user, Role $role) { $builder = $this->createFormBuilder()->add('userId', 'hidden', ['data' => $user->getId(), 'constraints' => [new NotBlank()]])->add('roleId', 'hidden', ['data' => $role->getId(), 'constraints' => [new NotBlank()]]); return $builder->getForm(); }
/** * @param array $data * @param RZ\Roadiz\Core\Entities\Role $role * * @return RZ\Roadiz\Core\Entities\Role */ protected function editRole(array $data, Role $role) { if ($role->required()) { throw new EntityRequiredException($this->getTranslator()->trans("role.required.cannot_be_updated"), 1); } if (isset($data['name'])) { $existing = $this->getService('em')->getRepository('RZ\\Roadiz\\Core\\Entities\\Role')->findOneBy(['name' => $data['name']]); if ($existing !== null && $existing->getId() != $role->getId()) { throw new EntityAlreadyExistsException($this->getTranslator()->trans("role.name.already.exists"), 1); } $role->setName($data['name']); $this->getService('em')->flush(); // Clear result cache $cacheDriver = $this->getService('em')->getConfiguration()->getResultCacheImpl(); if ($cacheDriver !== null) { $cacheDriver->deleteAll(); } return $role; } else { throw new \RuntimeException("Role name is not defined", 1); } return null; }
/** * @param array $data * @param RZ\Roadiz\Core\Entities\Group $group * @param RZ\Roadiz\Core\Entities\Role $role * * @return RZ\Roadiz\Core\Entities\Role */ private function removeRole($data, Group $group, Role $role) { if ($data['groupId'] == $group->getId() && $data['roleId'] == $role->getId()) { if ($role !== null) { $group->removeRole($role); $this->getService('em')->flush(); } return $role; } }