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

Use formattedValue on code editor detail to display JSON fields #5759

Merged
merged 1 commit into from
Jun 23, 2023

Conversation

rogercbe
Copy link
Contributor

Describe the bug
The documentation says to use TextField, TextAreaField or CodeEditorField field to display a Doctrine json type.

However, using CodeEditorField fails with:

Array to string conversion

This could be worked around by using ->formatValue(fn ($value) => json_encode($value)) but the template code_editor.html.twig does not use it for the DETAIL view.

The PR adds the formattedValue to the code_editor template so that it can be used

To Reproduce
EasyAdmin 4.6.1

  1. Create a doctrine entity with a json field
  2. Create a CrudController
  3. Try to use the json field in a view

Related Issues:
#5680
#4388

@ndench
Copy link
Contributor

ndench commented Jun 9, 2023

Any chance you could also update the documentation to remove TextField and TextAreaField from the recommendations for a Doctrine json type?

@javiereguiluz javiereguiluz added this to the 4.x milestone Jun 23, 2023
@javiereguiluz
Copy link
Collaborator

Roger, thanks a lot for fixing this bug!

@javiereguiluz javiereguiluz merged commit ad6328f into EasyCorp:4.x Jun 23, 2023
@rogercbe rogercbe deleted the display-json-field branch July 6, 2023 12:26
@conradfr
Copy link

conradfr commented Jun 17, 2024

Does not seem to work if the json has int as values.

And still get a An exception has been thrown during the rendering of a template ("Warning: Array to string conversion"). with CodeEditorField (4.10.2)

@gremo
Copy link
Contributor

gremo commented Jun 20, 2024

Doesn't not work also here, like @conradfr same exception thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants