-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[String] Add TruncateMode
mode to truncate
methods
#57243
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
Conversation
0cbd9ea
to
da24ab8
Compare
2efd0c4
to
003ffd8
Compare
This deprecation will deteriorate the DX when using String instances in twig 😐 Why not adding a second parameter that would dictate if the cut must happen before or after the word beeing cut in ? |
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.
As per curent naming conventions ?
31e0b07
to
d1f2750
Compare
I do not know how much it's being used within Twig, is it a very common function in there ? public function truncate(int $length, string $ellipsis = '', bool $cut = true, bool $strict = true): static
|
948e8e5
to
a2ec874
Compare
Yep absolutely right. But with the bool not beeing deprecated my point is obselete anyway :) And if we want, we can add a |truncate filter with bool or named parameter in Twig, that use the new Enums 👍 |
Just some suggestion regarding the names and docblock.. To me it seems easier to understand the use cases / differences... but feel free to ignore... as DX is always very personal :) |
a2ec874
to
e821bd5
Compare
Updated with @smnandre recommendations ! Thanks ❤️ |
- TruncateCut
+ TruncateMode ? Also the PR title needs some update |
e821bd5
to
6ea2181
Compare
6ea2181
to
76bf2c2
Compare
TruncateMode
mode to truncate
method
76bf2c2
to
1824b67
Compare
TruncateMode
mode to truncate
methodTruncateMode
mode to truncate
methods
1824b67
to
446358d
Compare
446358d
to
2458aa5
Compare
2458aa5
to
c3136a0
Compare
|
||
* `truncate` method now also accept `TruncateMode` enum instead of a boolean: | ||
* `TruncateMode::Char` is equivalent to `true` value ; | ||
* `TruncateMode::WordAfter` is equivalent to `true` 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.
* `TruncateMode::WordAfter` is equivalent to `true` value ; | |
* `TruncateMode::WordAfter` is equivalent to `false` value ; |
Thank you @Korbeil. |
When using truncate we had two behaviors:
But sometimes, I want the truncate to fit within 14 chars while keeping all complete words, so I changed truncate method to have a new mode "WordBefore" and switch the
cut
parameter to use a new enum so we can choose which mode is better.Now: