Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot configure CRUD field for doctrine entity with json member #6602

Open
mgiuffrida opened this issue Nov 28, 2024 · 0 comments
Open

Cannot configure CRUD field for doctrine entity with json member #6602

mgiuffrida opened this issue Nov 28, 2024 · 0 comments

Comments

@mgiuffrida
Copy link

mgiuffrida commented Nov 28, 2024

As described in #5680 , the docs recommend mapping json to TextField, TextareaField, or CodeEditorField.

The JSON field should be mapped back to a string, since the Doctrine entity treats it as an array via json_decode().

Even then, using either TextField or TextAreaField fails with a RuntimeException:

The value of the "foo" field of the entity with ID = "1" can't be converted into a string, so it cannot be represented by a TextField or a TextareaField.

  public function configureFields(string $pageName): iterable {
    return [
      ...,
      TextareaField::new('foo')
          ->formatValue(fn ($foo) => json_encode($foo)),
      ...,
  ] 
}

Using CodeEditorField works, thanks to #5759.

To Reproduce EasyAdmin 4.18.0

  1. Create a doctrine entity with a json field
  2. Create a CrudController as in the example above
  3. Try to view the entity in a template, e.g. a crud dashboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant