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

views_ui_truncate() is deprecated. #918

Open
github-actions bot opened this issue Oct 20, 2024 · 0 comments
Open

views_ui_truncate() is deprecated. #918

github-actions bot opened this issue Oct 20, 2024 · 0 comments
Labels

Comments

@github-actions
Copy link

https://www.drupal.org/node/3408283

Introduced in branch/version: 10.3.x / 10.3.0

views_ui_truncate() is deprecated. Use \Drupal\Component\Utility\Unicode::truncate() with parameter $add_ellipsis = TRUE instead.

Before

$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$new_string = views_ui_truncate($string, 13);
echo $new_string; // "Lorem ipsum d..."

After

$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$new_string = \Drupal\Component\Utility\Unicode::truncate($string, 13, FALSE, TRUE);
echo $new_string; // "Lorem ipsum d…"

//$wordsafe === TRUE
$new_string = \Drupal\Component\Utility\Unicode::truncate($string, 13, TRUE, TRUE);
echo $new_string; // "Lorem ipsum…"


Given a string longer than 80 characters:

- views_ui_truncate() cuts the string at the 80th character and adds 3 more characters, making the string 83 characters long.
- Unicode::truncate() depends on what parameters you give it.
* If $wordsafe parameter is FALSE, it cuts the string at 79 chars and adds the ellipsis, making it in total of 80 chars long.
* If $wordsafe === TRUE, it cuts it at the last word possible before the 80th character and adds the ellipsis, so it can happen that the final string won't be at 80 chars long

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

No branches or pull requests

0 participants