mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
fix deprecations: getName → getBlockPrefix or nothing
This commit is contained in:
parent
85018f1927
commit
af00cc4da6
@ -27,19 +27,19 @@ use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class CenterType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* The user linked with this type.
|
||||
* The user linked with this type.
|
||||
*
|
||||
* @var \Chill\MainBundle\Entity\User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
|
||||
/**
|
||||
* associative array where keys are center.id and
|
||||
* value are center objects
|
||||
@ -47,14 +47,14 @@ class CenterType extends AbstractType
|
||||
* @var Center[]
|
||||
*/
|
||||
protected $reachableCenters = array();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CenterTransformer
|
||||
*/
|
||||
protected $transformer;
|
||||
|
||||
public function __construct(TokenStorage $tokenStorage,
|
||||
|
||||
public function __construct(TokenStorage $tokenStorage,
|
||||
CenterTransformer $transformer)
|
||||
{
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
@ -62,23 +62,18 @@ class CenterType extends AbstractType
|
||||
$this->prepareReachableCenterByUser();
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'center';
|
||||
}
|
||||
|
||||
/**
|
||||
* return a 'hidden' field if only one center is available.
|
||||
*
|
||||
*
|
||||
* Return a 'choice' field if more than one center is available.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException if the user is not associated with any center
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
$nbReachableCenters = count($this->reachableCenters);
|
||||
|
||||
|
||||
if ($nbReachableCenters === 0) {
|
||||
throw new \RuntimeException("The user is not associated with "
|
||||
. "any center. Associate user with a center");
|
||||
@ -88,23 +83,23 @@ class CenterType extends AbstractType
|
||||
return 'entity';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* configure default options, i.e. add choices if user can reach multiple
|
||||
* centers.
|
||||
*
|
||||
*
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
{
|
||||
if (count($this->reachableCenters) > 1) {
|
||||
$resolver->setDefault('class', 'Chill\MainBundle\Entity\Center');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add a data transformer if user can reach only one center
|
||||
*
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
@ -114,21 +109,21 @@ class CenterType extends AbstractType
|
||||
$builder->addModelTransformer($this->transformer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* populate reachableCenters as an associative array where
|
||||
* keys are center.id and value are center entities.
|
||||
*
|
||||
*
|
||||
*/
|
||||
private function prepareReachableCenterByUser()
|
||||
{
|
||||
$groupCenters = $this->user->getGroupCenters();
|
||||
|
||||
|
||||
foreach ($groupCenters as $groupCenter) {
|
||||
|
||||
|
||||
$center = $groupCenter->getCenter();
|
||||
|
||||
if (!array_key_exists($center->getId(),
|
||||
|
||||
if (!array_key_exists($center->getId(),
|
||||
$this->reachableCenters)) {
|
||||
$this->reachableCenters[$center->getId()] = $center;
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ComposedGroupCenterType extends AbstractType
|
||||
{
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('permissionsgroup', 'entity', array(
|
||||
@ -48,13 +48,13 @@ class ComposedGroupCenterType extends AbstractType
|
||||
))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefault('data_class', 'Chill\MainBundle\Entity\GroupCenter');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'composed_groupcenter';
|
||||
}
|
||||
|
@ -43,25 +43,25 @@ class ComposedRoleScopeType extends AbstractType
|
||||
* @var string[]
|
||||
*/
|
||||
private $roles = array();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $rolesWithoutScope = array();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var RoleProvider
|
||||
*/
|
||||
private $roleProvider;
|
||||
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
RoleProvider $roleProvider
|
||||
@ -71,19 +71,19 @@ class ComposedRoleScopeType extends AbstractType
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->roleProvider = $roleProvider;
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
// store values used in internal function
|
||||
$translatableStringHelper = $this->translatableStringHelper;
|
||||
$rolesWithoutScopes = $this->rolesWithoutScope;
|
||||
|
||||
|
||||
//build roles
|
||||
$values = array();
|
||||
foreach ($this->roles as $role) {
|
||||
$values[$role] = $role;
|
||||
}
|
||||
|
||||
|
||||
$builder
|
||||
->add('role', 'choice', array(
|
||||
'choices' => $values,
|
||||
@ -107,14 +107,9 @@ class ComposedRoleScopeType extends AbstractType
|
||||
'required' => false,
|
||||
'data' => null
|
||||
));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'composed_role_scope';
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefault('data_class', 'Chill\MainBundle\Entity\RoleScope');
|
||||
|
@ -30,16 +30,16 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class Select2ChoiceType extends AbstractType
|
||||
{
|
||||
public function getName()
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_choice';
|
||||
}
|
||||
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return 'choice';
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(
|
||||
|
@ -44,14 +44,14 @@ class Select2CountryType extends AbstractType
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
|
||||
public function __construct(RequestStack $requestStack,ObjectManager $em)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_country';
|
||||
}
|
||||
@ -66,7 +66,7 @@ class Select2CountryType extends AbstractType
|
||||
{
|
||||
return 'select2_choice';
|
||||
}
|
||||
|
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$locale = $this->requestStack->getCurrentRequest()->getLocale();
|
||||
|
@ -30,16 +30,16 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class Select2EntityType extends AbstractType
|
||||
{
|
||||
public function getName()
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_entity';
|
||||
}
|
||||
|
||||
|
||||
public function getParent()
|
||||
{
|
||||
return 'entity';
|
||||
}
|
||||
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->replaceDefaults(
|
||||
|
@ -41,18 +41,18 @@ class Select2LanguageType extends AbstractType
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
|
||||
public function __construct(RequestStack $requestStack,ObjectManager $em)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'select2_chill_language';
|
||||
}
|
||||
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$transformer = new MultipleObjectsToIdTransformer($this->em,'Chill\MainBundle\Entity\Language');
|
||||
@ -63,7 +63,7 @@ class Select2LanguageType extends AbstractType
|
||||
{
|
||||
return 'select2_choice';
|
||||
}
|
||||
|
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$locale = $this->requestStack->getCurrentRequest()->getLocale();
|
||||
@ -81,4 +81,4 @@ class Select2LanguageType extends AbstractType
|
||||
'choices' => $choices
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ class TranslatableStringFormType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options) {
|
||||
foreach ($this->availableLanguages as $lang) {
|
||||
$builder->add($lang, 'text',
|
||||
array('required' => (in_array($lang,
|
||||
array('required' => (in_array($lang,
|
||||
$this->frameworkTranslatorFallback))));
|
||||
}
|
||||
}
|
||||
|
||||
public function getName()
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'translatable_string';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user