1

When clicking the "Edit" link in EasyAdmin's list view of an entity that contains a field with type="date", I'm getting this error message:

Unable to transform value for property path "birthday": Expected a string.

I have this in my entity:

/**
 * @ORM\Column(type="date")
 * @Assert\NotBlank()
 * @Assert\Date()
 */
private $birthday;
Thomas Landauer
  • 7,857
  • 10
  • 47
  • 99

1 Answers1

3

There are 2 solutions.

Quick and dirty (Symfony < 5)

Change this in config/packages/easy_admin.yaml:

easy_admin:
    entities:
        MyEntity:
            form:
                fields:
                    - { property: 'birthday', type: 'date' }

See https://symfony.com/doc/master/bundles/EasyAdminBundle/book/edit-new-configuration.html#the-special-form-view for further configuration details.

Quick and clean

@Assert\Date() will be deprecated for type="date" fields in Symfony 4.2 (and thus probably removed in Symfony 5). The validation relies on the \DateTimeInterface type hint of the setter. In total:

/**
 * @ORM\Column(type="date")
 * @Assert\NotBlank()
 */
private $birthday;

public function setBirthday(?\DateTimeInterface $birthday): self
{
    // ...
    return $this;
}

See https://github.com/EasyCorp/EasyAdminBundle/issues/2381 for some background information.

Thomas Landauer
  • 7,857
  • 10
  • 47
  • 99