By dimitriskr on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
10.3.x
Introduced in version:
10.3.0
Issue links:
Description:
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
Impacts:
Module developers