You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`
With a viewTransformer to transform ( I receive an array and i register a string in my database)
$builder->get('labels')->addViewTransformer(new TestLabelsTransformer());
/**
* @param mixed $value
* @return array
*/
public function reverseTransform($value)
{
if (is_array($value)) {
return implode(',', $value);
}
return $value;
}
With the 3.4.24, i have an invalid value. So I change my code to use a CollectionType instead of TextType and i add a transformer but I get this error : Expected argument of type "array or (\Traversable and \ArrayAccess)", "string" given when i try to use a ModelTransformer to convert an array to a string.
In my Form:
The validator catch the exception Type before passing by the ModelTransformer. ( With a patch method)
Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener
public function preSetData(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
// with the post
if (null === $data) {
$data = [];
}
// with patch $data = 'the string1,string2' sor it doesn't use the ModelTransformer
if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
}}
@Simperfit Yes I fixed it with a customType with multiple option, and i added a ModelTransformer to convert the array to string.
It seems to work fine Thanks
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected: 3.4.24
Hello,
When I upgrade my project from 3.3 to 3.4.24, I have some errors with form field and transformer.
with symfony 3.3 I had this code :
`
With a viewTransformer to transform ( I receive an array and i register a string in my database)
With the 3.4.24, i have an invalid value. So I change my code to use a CollectionType instead of TextType and i add a transformer but I get this error : Expected argument of type "array or (\Traversable and \ArrayAccess)", "string" given when i try to use a ModelTransformer to convert an array to a string.
In my Form:
The validator catch the exception Type before passing by the ModelTransformer. ( With a patch method)
the same error here #30622
Thank you
The text was updated successfully, but these errors were encountered: