-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
[PoC] Value formatters #649
base: 3.x
Are you sure you want to change the base?
Conversation
|
||
public function __construct( | ||
private string $trueLabel = self::LABEL_TRUE, | ||
private string $falseLabel = self::LABEL_FALSE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this translatable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I think this should be responsibility of something like a TranslationFormatter
. WDYT?
src/Formatter/IterableFormatter.php
Outdated
$value = iterator_to_array($value); | ||
} | ||
|
||
$data[$key] = '['.implode(', ', array_map([$this, 'formatFromIterable'], $value)).']'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we have this for quite a while, but do we need the brackets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the brackets are used here to represent an array structure instead of a colloquial list.
6decc95
to
896d4f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonata-project/contributors, I'd like to know your opinion about this approach before spending more time.
Thank you in advance.
896d4f6
to
87eae9f
Compare
I like the idea. But I'm not sure about the
part. If we have string formatter, we will have a risk to have some conflict with previous formatter (which already format some non-string data like boolean or date, to string). Shouldn't we have something like
|
Thanks for the quick reply.
I have the same concern, the intention of this item in the To Do list was to cover that:
About the |
4b54296
to
4f1deba
Compare
private int $batchSize = 100, | ||
bool $useBackedEnumValue = true, | ||
?bool $useBackedEnumValue = null, | ||
bool $disableSourceFormatters = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it false by default in the abstract and true by default here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, thanks (I guess it was preventing the new deprecations).
I'll be updating this soon.
Ok, so I thought about something like
This way a value is formatted only once. And we could provide a
I'll get "trans(true)" for the boolean (If I used a ChainFormatter) without impacting the "true" string. Not sure if I'm clear @phansys |
4f1deba
to
6d39c06
Compare
I think I get your point, thank you. |
6d39c06
to
6664124
Compare
6664124
to
c83714c
Compare
For the records, I'm dumping here some thoughts I currently have about this feature, but I'd like to debate later if this PR is merged:
|
That's why I wrote the code
By passing the key to suport/format method, it allows to have different behavior based on the column. |
Yes, but in this case IMO, building the mapping will not be so easy. In case of objects (like the ones returned by |
@phansys first i wanted to make an extra Issue about this, but then i thought i might comment it there too: when doing the DatetimeFormater, could you maybe add a Timezone change too? Like for example the Data is stored in UTC Time, but the Grid uses Sonata\IntlBundle to show it in User Time. could there be a Hook where Or would it be easier to just overwrite Edit: OR also change the Datetime Format depending on the User Locale? |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
A different idea I had right now is to feed the export data into Symfony Serializer Then we could use all the Normalizer Features we want But I need to brainstorm about that idea Hm for my Serializer idea, the getDataSourceIterator sadly already has translated keys, |
Subject
Introduce value formatters.
See #293 (comment).
I am targeting this branch, because these changes should respect BC.
Closes #293.
Changelog
To do
priority
is required (by instance, to translate a value after a previous formatting).SerializableFormatter
,TranslatableFormatter
, etc);Determine how to cover the recursion required by theIterableFormatter
formatter;