Remove custom definition (form.yaml).

This commit is contained in:
Pol Dellaiera 2021-05-06 21:34:02 +02:00
parent a9bdb1fe3b
commit 1f9b4ddd79
10 changed files with 232 additions and 139 deletions

View File

@ -32,34 +32,34 @@ use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\Entity\RoleScope; use Chill\MainBundle\Entity\RoleScope;
/** /**
* Helper for authorizations. * Helper for authorizations.
* *
* Provides methods for user and entities information. * Provides methods for user and entities information.
* *
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
class AuthorizationHelper class AuthorizationHelper implements AuthorizationHelperInterface
{ {
/** /**
* *
* @var RoleHierarchyInterface * @var RoleHierarchyInterface
*/ */
protected $roleHierarchy; protected $roleHierarchy;
/** /**
* The role in a hierarchy, given by the parameter * The role in a hierarchy, given by the parameter
* `security.role_hierarchy.roles` from the container. * `security.role_hierarchy.roles` from the container.
* *
* @var string[] * @var string[]
*/ */
protected $hierarchy; protected $hierarchy;
/** /**
* *
* @var EntityManagerInterface * @var EntityManagerInterface
*/ */
protected $em; protected $em;
public function __construct( public function __construct(
RoleHierarchyInterface $roleHierarchy, RoleHierarchyInterface $roleHierarchy,
$hierarchy, $hierarchy,
@ -69,10 +69,10 @@ class AuthorizationHelper
$this->hierarchy = $hierarchy; $this->hierarchy = $hierarchy;
$this->em = $em; $this->em = $em;
} }
/** /**
* Determines if a user is active on this center * Determines if a user is active on this center
* *
* @param User $user * @param User $user
* @param Center $center * @param Center $center
* @return bool * @return bool
@ -81,21 +81,21 @@ class AuthorizationHelper
{ {
foreach ($user->getGroupCenters() as $groupCenter) { foreach ($user->getGroupCenters() as $groupCenter) {
if ($center->getId() === $groupCenter->getCenter()->getId()) { if ($center->getId() === $groupCenter->getCenter()->getId()) {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
* *
* Determines if the user has access to the given entity. * Determines if the user has access to the given entity.
* *
* if the entity implements Chill\MainBundle\Entity\HasScopeInterface, * if the entity implements Chill\MainBundle\Entity\HasScopeInterface,
* the scope is taken into account. * the scope is taken into account.
* *
* @param User $user * @param User $user
* @param HasCenterInterface $entity the entity may also implement HasScopeInterface * @param HasCenterInterface $entity the entity may also implement HasScopeInterface
* @param string|Role $attribute * @param string|Role $attribute
@ -103,15 +103,15 @@ class AuthorizationHelper
*/ */
public function userHasAccess(User $user, HasCenterInterface $entity, $attribute) public function userHasAccess(User $user, HasCenterInterface $entity, $attribute)
{ {
$center = $entity->getCenter(); $center = $entity->getCenter();
if (!$this->userCanReachCenter($user, $center)) { if (!$this->userCanReachCenter($user, $center)) {
return false; return false;
} }
$role = ($attribute instanceof Role) ? $attribute : new Role($attribute); $role = ($attribute instanceof Role) ? $attribute : new Role($attribute);
foreach ($user->getGroupCenters() as $groupCenter){ foreach ($user->getGroupCenters() as $groupCenter){
//filter on center //filter on center
if ($groupCenter->getCenter()->getId() === $entity->getCenter()->getId()) { if ($groupCenter->getCenter()->getId() === $entity->getCenter()->getId()) {
@ -119,7 +119,7 @@ class AuthorizationHelper
//iterate on roleScopes //iterate on roleScopes
foreach($permissionGroup->getRoleScopes() as $roleScope) { foreach($permissionGroup->getRoleScopes() as $roleScope) {
//check that the role allow to reach the required role //check that the role allow to reach the required role
if ($this->isRoleReached($role, if ($this->isRoleReached($role,
new Role($roleScope->getRole()))){ new Role($roleScope->getRole()))){
//if yes, we have a right on something... //if yes, we have a right on something...
// perform check on scope if necessary // perform check on scope if necessary
@ -137,17 +137,17 @@ class AuthorizationHelper
} }
} }
} }
} }
} }
return false; return false;
} }
/** /**
* Get reachable Centers for the given user, role, * Get reachable Centers for the given user, role,
* and optionnaly Scope * and optionnaly Scope
* *
* @param User $user * @param User $user
* @param Role $role * @param Role $role
* @param null|Scope $scope * @param null|Scope $scope
@ -156,13 +156,13 @@ class AuthorizationHelper
public function getReachableCenters(User $user, Role $role, Scope $scope = null) public function getReachableCenters(User $user, Role $role, Scope $scope = null)
{ {
$centers = array(); $centers = array();
foreach ($user->getGroupCenters() as $groupCenter){ foreach ($user->getGroupCenters() as $groupCenter){
$permissionGroup = $groupCenter->getPermissionsGroup(); $permissionGroup = $groupCenter->getPermissionsGroup();
//iterate on roleScopes //iterate on roleScopes
foreach($permissionGroup->getRoleScopes() as $roleScope) { foreach($permissionGroup->getRoleScopes() as $roleScope) {
//check that the role is in the reachable roles //check that the role is in the reachable roles
if ($this->isRoleReached($role, if ($this->isRoleReached($role,
new Role($roleScope->getRole()))) { new Role($roleScope->getRole()))) {
if ($scope === null) { if ($scope === null) {
$centers[] = $groupCenter->getCenter(); $centers[] = $groupCenter->getCenter();
@ -171,19 +171,19 @@ class AuthorizationHelper
if ($scope->getId() == $roleScope->getScope()->getId()){ if ($scope->getId() == $roleScope->getScope()->getId()){
$centers[] = $groupCenter->getCenter(); $centers[] = $groupCenter->getCenter();
break 1; break 1;
} }
} }
} }
} }
} }
return $centers; return $centers;
} }
/** /**
* Return all reachable scope for a given user, center and role * Return all reachable scope for a given user, center and role
* *
* @deprecated Use getReachableCircles * @deprecated Use getReachableCircles
* *
* @param User $user * @param User $user
@ -195,10 +195,10 @@ class AuthorizationHelper
{ {
return $this->getReachableCircles($user, $role, $center); return $this->getReachableCircles($user, $role, $center);
} }
/** /**
* Return all reachable circle for a given user, center and role * Return all reachable circle for a given user, center and role
* *
* @param User $user * @param User $user
* @param Role $role * @param Role $role
* @param Center $center * @param Center $center
@ -207,7 +207,7 @@ class AuthorizationHelper
public function getReachableCircles(User $user, Role $role, Center $center) public function getReachableCircles(User $user, Role $role, Center $center)
{ {
$scopes = array(); $scopes = array();
foreach ($user->getGroupCenters() as $groupCenter){ foreach ($user->getGroupCenters() as $groupCenter){
if ($center->getId() === $groupCenter->getCenter()->getId()) { if ($center->getId() === $groupCenter->getCenter()->getId()) {
//iterate on permissionGroup //iterate on permissionGroup
@ -215,7 +215,7 @@ class AuthorizationHelper
//iterate on roleScopes //iterate on roleScopes
foreach($permissionGroup->getRoleScopes() as $roleScope) { foreach($permissionGroup->getRoleScopes() as $roleScope) {
//check that the role is in the reachable roles //check that the role is in the reachable roles
if ($this->isRoleReached($role, if ($this->isRoleReached($role,
new Role($roleScope->getRole()))) { new Role($roleScope->getRole()))) {
$scopes[] = $roleScope->getScope(); $scopes[] = $roleScope->getScope();
@ -223,12 +223,12 @@ class AuthorizationHelper
} }
} }
} }
return $scopes; return $scopes;
} }
/** /**
* *
* @param Role $role * @param Role $role
* @param Center $center * @param Center $center
* @param Scope $circle * @param Scope $circle
@ -239,7 +239,7 @@ class AuthorizationHelper
$parents = $this->getParentRoles($role); $parents = $this->getParentRoles($role);
$parents[] = $role; $parents[] = $role;
$parentRolesString = \array_map(function(Role $r) { return $r->getRole(); }, $parents); $parentRolesString = \array_map(function(Role $r) { return $r->getRole(); }, $parents);
$qb = $this->em->createQueryBuilder(); $qb = $this->em->createQueryBuilder();
$qb $qb
->select('u') ->select('u')
@ -250,21 +250,21 @@ class AuthorizationHelper
->where('gc.center = :center') ->where('gc.center = :center')
->andWhere($qb->expr()->in('rs.role', $parentRolesString)) ->andWhere($qb->expr()->in('rs.role', $parentRolesString))
; ;
$qb->setParameter('center', $center); $qb->setParameter('center', $center);
if ($circle !== null) { if ($circle !== null) {
$qb->andWhere('rs.scope = :circle') $qb->andWhere('rs.scope = :circle')
->setParameter('circle', $circle) ->setParameter('circle', $circle)
; ;
} }
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }
/** /**
* Test if a parent role may give access to a given child role * Test if a parent role may give access to a given child role
* *
* @param Role $childRole The role we want to test if he is reachable * @param Role $childRole The role we want to test if he is reachable
* @param Role $parentRole The role which should give access to $childRole * @param Role $parentRole The role which should give access to $childRole
* @return boolean true if the child role is granted by parent role * @return boolean true if the child role is granted by parent role
@ -273,14 +273,14 @@ class AuthorizationHelper
{ {
$reachableRoles = $this->roleHierarchy $reachableRoles = $this->roleHierarchy
->getReachableRoles([$parentRole]); ->getReachableRoles([$parentRole]);
return in_array($childRole, $reachableRoles); return in_array($childRole, $reachableRoles);
} }
/** /**
* Return all the role which give access to the given role. Only the role * Return all the role which give access to the given role. Only the role
* which are registered into Chill are taken into account. * which are registered into Chill are taken into account.
* *
* @param Role $role * @param Role $role
* @return Role[] the role which give access to the given $role * @return Role[] the role which give access to the given $role
*/ */
@ -291,18 +291,18 @@ class AuthorizationHelper
$roles = \array_map( $roles = \array_map(
function($string) { function($string) {
return new Role($string); return new Role($string);
}, },
\array_keys($this->hierarchy) \array_keys($this->hierarchy)
); );
foreach ($roles as $r) { foreach ($roles as $r) {
$childRoles = $this->roleHierarchy->getReachableRoleNames([$r->getRole()]); $childRoles = $this->roleHierarchy->getReachableRoleNames([$r->getRole()]);
if (\in_array($role, $childRoles)) { if (\in_array($role, $childRoles)) {
$parentRoles[] = $r; $parentRoles[] = $r;
} }
} }
return $parentRoles; return $parentRoles;
} }
} }

View File

@ -0,0 +1,87 @@
<?php
namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\HasCenterInterface;
use Symfony\Component\Security\Core\Role\Role;
use Chill\MainBundle\Entity\Scope;
interface AuthorizationHelperInterface
{
/**
* Determines if a user is active on this center
*
* @param User $user
* @param Center $center
* @return bool
*/
public function userCanReachCenter(User $user, Center $center);
/**
*
* Determines if the user has access to the given entity.
*
* if the entity implements Chill\MainBundle\Entity\HasScopeInterface,
* the scope is taken into account.
*
* @param User $user
* @param HasCenterInterface $entity the entity may also implement HasScopeInterface
* @param string|Role $attribute
* @return boolean true if the user has access
*/
public function userHasAccess(User $user, HasCenterInterface $entity, $attribute);
/**
* Get reachable Centers for the given user, role,
* and optionnaly Scope
*
* @param User $user
* @param Role $role
* @param null|Scope $scope
* @return Center[]
*/
public function getReachableCenters(User $user, Role $role, Scope $scope = null);
/**
* Return all reachable scope for a given user, center and role
*
* @deprecated Use getReachableCircles
*
* @param User $user
* @param Role $role
* @param Center $center
* @return Scope[]
*/
public function getReachableScopes(User $user, Role $role, Center $center);
/**
* Return all reachable circle for a given user, center and role
*
* @param User $user
* @param Role $role
* @param Center $center
* @return Scope[]
*/
public function getReachableCircles(User $user, Role $role, Center $center);
/**
*
* @param Role $role
* @param Center $center
* @param Scope $circle
* @return Users
*/
public function findUsersReaching(Role $role, Center $center, Scope $circle = null);
/**
* Return all the role which give access to the given role. Only the role
* which are registered into Chill are taken into account.
*
* @param Role $role
* @return Role[] the role which give access to the given $role
*/
public function getParentRoles(Role $role);
}

View File

@ -2,7 +2,7 @@
/* /*
* Chill is a software for social workers * Chill is a software for social workers
* *
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS, * Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop> * <http://www.champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -28,18 +28,18 @@ use Twig\TwigFilter;
* *
* @package Chill\MainBundle\Templating\Entity * @package Chill\MainBundle\Templating\Entity
*/ */
class ChillEntityRenderExtension extends AbstractExtension class ChillEntityRenderExtension extends AbstractExtension implements ChillEntityRenderExtensionInterface
{ {
/** /**
* @var ChillEntityRenderInterface * @var ChillEntityRenderInterface
*/ */
protected $renders = []; protected $renders = [];
/** /**
* @var ChillEntityRender * @var ChillEntityRender
*/ */
protected $defaultRender; protected $defaultRender;
/** /**
* ChillEntityRenderExtension constructor. * ChillEntityRenderExtension constructor.
*/ */
@ -47,7 +47,7 @@ class ChillEntityRenderExtension extends AbstractExtension
{ {
$this->defaultRender = new ChillEntityRender(); $this->defaultRender = new ChillEntityRender();
} }
/** /**
* @return array|TwigFilter[] * @return array|TwigFilter[]
*/ */
@ -62,7 +62,7 @@ class ChillEntityRenderExtension extends AbstractExtension
]) ])
]; ];
} }
/** /**
* @param $entity * @param $entity
* @param array $options * @param array $options
@ -76,7 +76,7 @@ class ChillEntityRenderExtension extends AbstractExtension
return $this->getRender($entity, $options) return $this->getRender($entity, $options)
->renderString($entity, $options); ->renderString($entity, $options);
} }
/** /**
* @param $entity * @param $entity
* @param array $options * @param array $options
@ -90,7 +90,7 @@ class ChillEntityRenderExtension extends AbstractExtension
return $this->getRender($entity, $options) return $this->getRender($entity, $options)
->renderBox($entity, $options); ->renderBox($entity, $options);
} }
/** /**
* @param ChillEntityRenderInterface $render * @param ChillEntityRenderInterface $render
*/ */
@ -98,7 +98,7 @@ class ChillEntityRenderExtension extends AbstractExtension
{ {
$this->renders[] = $render; $this->renders[] = $render;
} }
/** /**
* @param $entity * @param $entity
* @param $options * @param $options

View File

@ -0,0 +1,33 @@
<?php
namespace Chill\MainBundle\Templating\Entity;
use Twig\Extension\ExtensionInterface;
use Twig\TwigFilter;
interface ChillEntityRenderExtensionInterface extends ExtensionInterface
{
/**
* @return array|TwigFilter[]
*/
public function getFilters();
/**
* @param $entity
* @param array $options
* @return string
*/
public function renderString($entity, array $options = []): string;
/**
* @param $entity
* @param array $options
* @return string
*/
public function renderBox($entity, array $options = []): string;
/**
* @param ChillEntityRenderInterface $render
*/
public function addRender(ChillEntityRenderInterface $render);
}

View File

@ -1,4 +1,4 @@
services: services:
chill.main.security.authorization.helper: chill.main.security.authorization.helper:
class: Chill\MainBundle\Security\Authorization\AuthorizationHelper class: Chill\MainBundle\Security\Authorization\AuthorizationHelper
arguments: arguments:
@ -6,47 +6,48 @@ services:
$hierarchy: "%security.role_hierarchy.roles%" $hierarchy: "%security.role_hierarchy.roles%"
$em: '@Doctrine\ORM\EntityManagerInterface' $em: '@Doctrine\ORM\EntityManagerInterface'
Chill\MainBundle\Security\Authorization\AuthorizationHelper: '@chill.main.security.authorization.helper' Chill\MainBundle\Security\Authorization\AuthorizationHelper: '@chill.main.security.authorization.helper'
Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface: Chill\MainBundle\Security\Authorization\AuthorizationHelper
chill.main.role_provider: chill.main.role_provider:
class: Chill\MainBundle\Security\RoleProvider class: Chill\MainBundle\Security\RoleProvider
chill.main.user_provider: chill.main.user_provider:
class: Chill\MainBundle\Security\UserProvider\UserProvider class: Chill\MainBundle\Security\UserProvider\UserProvider
arguments: arguments:
$em: '@Doctrine\ORM\EntityManagerInterface' $em: '@Doctrine\ORM\EntityManagerInterface'
Chill\MainBundle\Security\Authorization\ChillExportVoter: Chill\MainBundle\Security\Authorization\ChillExportVoter:
arguments: arguments:
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper' $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
tags: tags:
- { name: security.voter } - { name: security.voter }
Chill\MainBundle\Security\PasswordRecover\TokenManager: Chill\MainBundle\Security\PasswordRecover\TokenManager:
arguments: arguments:
$secret: '%kernel.secret%' $secret: '%kernel.secret%'
$logger: '@Psr\Log\LoggerInterface' $logger: '@Psr\Log\LoggerInterface'
Chill\MainBundle\Security\PasswordRecover\RecoverPasswordHelper: Chill\MainBundle\Security\PasswordRecover\RecoverPasswordHelper:
arguments: arguments:
$tokenManager: '@Chill\MainBundle\Security\PasswordRecover\TokenManager' $tokenManager: '@Chill\MainBundle\Security\PasswordRecover\TokenManager'
$urlGenerator: '@Symfony\Component\Routing\Generator\UrlGeneratorInterface' $urlGenerator: '@Symfony\Component\Routing\Generator\UrlGeneratorInterface'
$mailer: '@Chill\MainBundle\Notification\Mailer' $mailer: '@Chill\MainBundle\Notification\Mailer'
$routeParameters: "%chill_main.notifications%" $routeParameters: "%chill_main.notifications%"
Chill\MainBundle\Security\PasswordRecover\PasswordRecoverEventSubscriber: Chill\MainBundle\Security\PasswordRecover\PasswordRecoverEventSubscriber:
arguments: arguments:
$locker: '@Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker' $locker: '@Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker'
tags: tags:
- { name: kernel.event_subscriber } - { name: kernel.event_subscriber }
Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker: Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker:
arguments: arguments:
$chillRedis: '@Chill\MainBundle\Redis\ChillRedis' $chillRedis: '@Chill\MainBundle\Redis\ChillRedis'
$logger: '@Psr\Log\LoggerInterface' $logger: '@Psr\Log\LoggerInterface'
Chill\MainBundle\Security\PasswordRecover\PasswordRecoverVoter: Chill\MainBundle\Security\PasswordRecover\PasswordRecoverVoter:
arguments: arguments:
$locker: '@Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker' $locker: '@Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker'
$requestStack: '@Symfony\Component\HttpFoundation\RequestStack' $requestStack: '@Symfony\Component\HttpFoundation\RequestStack'
tags: tags:
- { name: security.voter } - { name: security.voter }

View File

@ -30,6 +30,7 @@ services:
Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension: Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension:
tags: tags:
- { name: twig.extension } - { name: twig.extension }
Chill\MainBundle\Templating\Entity\ChillEntityRenderExtensionInterface: Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension
Chill\MainBundle\Templating\Entity\CommentRender: Chill\MainBundle\Templating\Entity\CommentRender:
arguments: arguments:
@ -37,7 +38,7 @@ services:
- '@Symfony\Component\Templating\EngineInterface' - '@Symfony\Component\Templating\EngineInterface'
tags: tags:
- { name: 'chill.render_entity' } - { name: 'chill.render_entity' }
Chill\MainBundle\Templating\ChillMarkdownRenderExtension: Chill\MainBundle\Templating\ChillMarkdownRenderExtension:
tags: tags:
- { name: twig.extension } - { name: twig.extension }

View File

@ -13,30 +13,3 @@ services:
- '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' - '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
tags: tags:
- { name: form.type, alias: '@chill.main.form.person_creation' } - { name: form.type, alias: '@chill.main.form.person_creation' }
chill.person.accompanying_period_closing_motive:
class: Chill\PersonBundle\Form\Type\ClosingMotivePickerType
arguments:
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
$chillEntityRenderExtension: '@Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension'
$closingMotiveRepository: '@Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository'
tags:
- { name: form.type, alias: closing_motive }
chill.person.form.type.pick_person:
class: Chill\PersonBundle\Form\Type\PickPersonType
arguments:
- Chill\PersonBundle\Repository\PersonRepository"
- "@security.token_storage"
- "@chill.main.security.authorization.helper"
- '@Symfony\Component\Routing\Generator\UrlGeneratorInterface'
- '@Symfony\Component\Translation\TranslatorInterface'
tags:
- { name: form.type }
Chill\PersonBundle\Form\Type\PersonAltNameType:
arguments:
$configHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper'
$translatableStringHelper: '@chill.main.helper.translatable_string'
tags:
- { name: form.type }

View File

@ -3,13 +3,11 @@
namespace Chill\PersonBundle\Form\Type; namespace Chill\PersonBundle\Form\Type;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtensionInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\Options;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository; use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository;
@ -23,12 +21,12 @@ class ClosingMotivePickerType extends AbstractType
{ {
/** /**
* @var TranslatableStringHelper * @var TranslatableStringHelperInterface
*/ */
protected $translatableStringHelper; protected $translatableStringHelper;
/** /**
* @var ChillEntityRenderExtension * @var ChillEntityRenderExtensionInterface
*/ */
protected $entityRenderExtension; protected $entityRenderExtension;
@ -40,20 +38,20 @@ class ClosingMotivePickerType extends AbstractType
/** /**
* ClosingMotivePickerType constructor. * ClosingMotivePickerType constructor.
* *
* @param TranslatableStringHelper $translatableStringHelper * @param TranslatableStringHelperInterface $translatableStringHelper
* @param ChillEntityRenderExtension $chillEntityRenderExtension * @param ChillEntityRenderExtensionInterface $chillEntityRenderExtension
* @param ClosingMotiveRepository $closingMotiveRepository * @param ClosingMotiveRepository $closingMotiveRepository
*/ */
public function __construct( public function __construct(
TranslatableStringHelper $translatableStringHelper, TranslatableStringHelperInterface $translatableStringHelper,
ChillEntityRenderExtension $chillEntityRenderExtension, ChillEntityRenderExtensionInterface $chillEntityRenderExtension,
ClosingMotiveRepository $closingMotiveRepository ClosingMotiveRepository $closingMotiveRepository
) { ) {
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->entityRenderExtension = $chillEntityRenderExtension; $this->entityRenderExtension = $chillEntityRenderExtension;
$this->repository = $closingMotiveRepository; $this->repository = $closingMotiveRepository;
} }
/** /**
* @return string * @return string
*/ */
@ -61,7 +59,7 @@ class ClosingMotivePickerType extends AbstractType
{ {
return 'closing_motive'; return 'closing_motive';
} }
/** /**
* @return null|string * @return null|string
*/ */
@ -69,13 +67,13 @@ class ClosingMotivePickerType extends AbstractType
{ {
return EntityType::class; return EntityType::class;
} }
/** /**
* @param OptionsResolver $resolver * @param OptionsResolver $resolver
*/ */
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'class' => ClosingMotive::class, 'class' => ClosingMotive::class,
'empty_data' => null, 'empty_data' => null,
@ -85,7 +83,7 @@ class ClosingMotivePickerType extends AbstractType
}, },
'only_leaf' => true 'only_leaf' => true
]); ]);
$resolver $resolver
->setAllowedTypes('only_leaf', 'bool') ->setAllowedTypes('only_leaf', 'bool')
->setNormalizer('choices', function (Options $options) { ->setNormalizer('choices', function (Options $options) {

View File

@ -7,30 +7,30 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelperInterface;
/** /**
* *
* *
*/ */
class PersonAltNameType extends AbstractType class PersonAltNameType extends AbstractType
{ {
/** /**
* *
* @var ConfigPersonAltNamesHelper * @var TranslatableStringHelperInterface
*/ */
private $configHelper; private $configHelper;
/** /**
* *
* @var TranslatableStringHelper * @var TranslatableStringHelperInterface
*/ */
private $translatableStringHelper; private $translatableStringHelper;
public function __construct( public function __construct(
ConfigPersonAltNamesHelper $configHelper, ConfigPersonAltNamesHelperInterface $configHelper,
TranslatableStringHelper $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper
) { ) {
$this->configHelper = $configHelper; $this->configHelper = $configHelper;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
@ -40,26 +40,26 @@ class PersonAltNameType extends AbstractType
{ {
foreach ($this->getKeyChoices() as $label => $key) { foreach ($this->getKeyChoices() as $label => $key) {
$builder->add( $builder->add(
$key, $key,
$options['force_hidden'] ? HiddenType::class : TextType::class, [ $options['force_hidden'] ? HiddenType::class : TextType::class, [
'label' => $label, 'label' => $label,
'required' => false 'required' => false
]); ]);
} }
$builder->setDataMapper(new \Chill\PersonBundle\Form\DataMapper\PersonAltNameDataMapper()); $builder->setDataMapper(new \Chill\PersonBundle\Form\DataMapper\PersonAltNameDataMapper());
} }
protected function getKeyChoices() protected function getKeyChoices()
{ {
$choices = $this->configHelper->getChoices(); $choices = $this->configHelper->getChoices();
$translatedChoices = []; $translatedChoices = [];
foreach ($choices as $key => $labels) { foreach ($choices as $key => $labels) {
$label = $this->translatableStringHelper->localize($labels); $label = $this->translatableStringHelper->localize($labels);
$translatedChoices[$label] = $key; $translatedChoices[$label] = $key;
} }
return $translatedChoices; return $translatedChoices;
} }

View File

@ -29,8 +29,8 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Chill\MainBundle\Entity\GroupCenter; use Chill\MainBundle\Entity\GroupCenter;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Search\PersonSearch; use Chill\PersonBundle\Search\PersonSearch;
use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Translation\TranslatorInterface;
@ -59,7 +59,7 @@ class PickPersonType extends AbstractType
* @var PersonRepository * @var PersonRepository
*/ */
protected $personRepository; protected $personRepository;
/** /**
* *
* @var \Chill\MainBundle\Entity\User * @var \Chill\MainBundle\Entity\User
@ -68,16 +68,16 @@ class PickPersonType extends AbstractType
/** /**
* *
* @var AuthorizationHelper * @var AuthorizationHelperInterface
*/ */
protected $authorizationHelper; protected $authorizationHelper;
/** /**
* *
* @var UrlGeneratorInterface * @var UrlGeneratorInterface
*/ */
protected $urlGenerator; protected $urlGenerator;
/** /**
* *
* @var TranslatorInterface * @var TranslatorInterface
@ -87,7 +87,7 @@ class PickPersonType extends AbstractType
public function __construct( public function __construct(
PersonRepository $personRepository, PersonRepository $personRepository,
TokenStorageInterface $tokenStorage, TokenStorageInterface $tokenStorage,
AuthorizationHelper $authorizationHelper, AuthorizationHelperInterface $authorizationHelper,
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
TranslatorInterface $translator TranslatorInterface $translator
) )
@ -133,7 +133,7 @@ class PickPersonType extends AbstractType
$selectedCenters[] = $c; $selectedCenters[] = $c;
} }
} }
return $selectedCenters; return $selectedCenters;
} }
@ -165,7 +165,7 @@ class PickPersonType extends AbstractType
'attr' => array('class' => 'select2 '), 'attr' => array('class' => 'select2 '),
'choice_loader' => function(Options $options) { 'choice_loader' => function(Options $options) {
$centers = $this->filterCentersfom($options); $centers = $this->filterCentersfom($options);
return new PersonChoiceLoader($this->personRepository, $centers); return new PersonChoiceLoader($this->personRepository, $centers);
} }
)); ));
@ -175,7 +175,7 @@ class PickPersonType extends AbstractType
{ {
return EntityType::class; return EntityType::class;
} }
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options) public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
{ {
$view->vars['attr']['data-person-picker'] = true; $view->vars['attr']['data-person-picker'] = true;