Add DateIntervalField for editable, localized DateInterval rendering#7596
Open
Amoifr wants to merge 1 commit intoEasyCorp:5.xfrom
Open
Add DateIntervalField for editable, localized DateInterval rendering#7596Amoifr wants to merge 1 commit intoEasyCorp:5.xfrom
Amoifr wants to merge 1 commit intoEasyCorp:5.xfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #7374
Storing a
DateInterval(Doctrinedateintervaltype) in aTextFieldcurrently breaks the page withThe value of the "..." field can't be converted into a string. The doc itself recommendedTextFieldfor this Doctrine type, which doesn't actually work.This PR introduces a dedicated
DateIntervalField, following the plan @javiereguiluz outlined in the issue:P1Y2M3D,PT1H30M, etc.). Powered by Symfony's built-inDateIntervalTypewithwidget => single_textandinput => dateinterval, so we don't have to maintain a custom transformer.2 years 4 days 6 hours 8 minutes). Each part uses adate_interval.*translation key with the standard Symfony pluralization syntax ({1} %count% year|]1,Inf] %count% years), so locales handle their own grammar.Per-field opt-out:
setFormat('%y years…')falls back to rawDateInterval::format(). Same applies toCrud::setDateIntervalFormat(), which existed already as a stub but was never read by anything.Other changes in this PR:
doc/fields.rst: the Doctrinedateintervalrow now points toDateIntervalFieldinstead of the (broken)TextFieldrecommendation, and the new field is added to the field list.doc/fields/DateIntervalField.rst: new dedicated doc page.translations/EasyAdminBundle.{en,fr}.php+ 36 other locales: newdate_interval.*keys (English placeholder for non-EN/FR per AGENTS.md guidance).src/Dto/CrudDto::$dateIntervalFormat: default switched from the (unused) hardcoded English string tonull, so the configurator can distinguish "no override → render localized" from "explicit format → raw DateInterval::format()". The publicCrud::setDateIntervalFormat(string)signature is unchanged.Test plan
tests/Unit/Field/DateIntervalFieldTest.php: 5 new tests cover null value, no-format → sentinel + value preserved, per-fieldsetFormat(), template pluralization (1 year + 2 months + 3 days + 4 hours + 5 minutes + 6 seconds), and zero-duration empty label.tests/Unit/Field/(610 tests) pass.pdo_sqlitewas unavailable in my local env, so the existing functionalDateIntervalFormatTest(which already only asserts the page renders) wasn't run here, but it still relies on the sameCrud::setDateIntervalFormat()API I left untouched.