mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
Fix Create a PickUserGroupOrUserDynamicType
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Chill\MainBundle\Form\Type\DataTransformer;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserGroup;
|
||||
use Chill\MainBundle\Serializer\Normalizer\DiscriminatedObjectDenormalizer;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
@@ -76,15 +77,22 @@ class EntityToJsonTransformer implements DataTransformerInterface
|
||||
'person' => Person::class,
|
||||
'thirdparty' => ThirdParty::class,
|
||||
'user_group' => UserGroup::class,
|
||||
'user_group_or_user' => DiscriminatedObjectDenormalizer::TYPE,
|
||||
default => throw new \UnexpectedValueException('This type is not supported'),
|
||||
};
|
||||
|
||||
$context = [AbstractNormalizer::GROUPS => ['read']];
|
||||
|
||||
if ('user_group_or_user' === $this->type) {
|
||||
$context[DiscriminatedObjectDenormalizer::ALLOWED_TYPES] = [UserGroup::class, User::class];
|
||||
}
|
||||
|
||||
return
|
||||
$this->denormalizer->denormalize(
|
||||
['type' => $item['type'], 'id' => $item['id']],
|
||||
$class,
|
||||
'json',
|
||||
[AbstractNormalizer::GROUPS => ['read']],
|
||||
$context,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ final class PickUserGroupOrUserDynamicType extends AbstractType
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'user_group'));
|
||||
$builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'user_group_or_user'));
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
|
Reference in New Issue
Block a user