Commit ea325a90 authored by alexpott's avatar alexpott

Issue #2361745 by rpayanm, javivf: Remove usage of truncate_utf8().

parent 6bf79095
......@@ -11,6 +11,7 @@
use Drupal\aggregator\Plugin\AggregatorPluginSettingsBase;
use Drupal\aggregator\Plugin\ProcessorInterface;
use Drupal\aggregator\FeedInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Database;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DateFormatter;
......@@ -213,8 +214,8 @@ public function process(FeedInterface $feed) {
}
// Make sure the item title and author fit in the 255 varchar column.
$entry->setTitle(truncate_utf8($item['title'], 255, TRUE, TRUE));
$entry->setAuthor(truncate_utf8($item['author'], 255, TRUE, TRUE));
$entry->setTitle(Unicode::truncate($item['title'], 255, TRUE, TRUE));
$entry->setAuthor(Unicode::truncate($item['author'], 255, TRUE, TRUE));
$entry->setFeedId($feed->id());
$entry->setLink($item['link']);
......
......@@ -297,7 +297,7 @@ private function doUser() {
$this->assertLogMessage(t('Session closed for %name.', array('%name' => $name)), 'DBLog event was recorded: [logout user]');
// Delete user.
$message = t('Deleted user: %name %email.', array('%name' => $name, '%email' => '<' . $user->getEmail() . '>'));
$message_text = truncate_utf8(Xss::filter($message, array()), 56, TRUE, TRUE);
$message_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE);
// Verify that the full message displays on the details page.
$link = FALSE;
if ($links = $this->xpath('//a[text()="' . html_entity_decode($message_text) . '"]')) {
......@@ -650,7 +650,7 @@ protected function asText(\SimpleXMLElement $element) {
* The message to pass to simpletest.
*/
protected function assertLogMessage($log_message, $message) {
$message_text = truncate_utf8(Xss::filter($log_message, array()), 56, TRUE, TRUE);
$message_text = Unicode::truncate(Xss::filter($log_message, array()), 56, TRUE, TRUE);
// After \Drupal\Component\Utility\Xss::filter(), HTML entities should be
// converted to their character equivalents because assertLink() uses this
// string in xpath() to query the Document Object Model (DOM).
......
......@@ -8,6 +8,7 @@
namespace Drupal\field_ui;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityListBuilderInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -228,7 +229,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
'@label' => $info['label'],
'@field' => $info['field'],
));
$existing_field_options[$field_name] = truncate_utf8($text, 80, FALSE, TRUE);
$existing_field_options[$field_name] = Unicode::truncate($text, 80, FALSE, TRUE);
}
asort($existing_field_options);
$name = '_add_existing_field';
......
......@@ -8,6 +8,7 @@
namespace Drupal\link\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -142,7 +143,7 @@ public function viewElements(FieldItemListInterface $items) {
// Trim the link text to the desired length.
if (!empty($settings['trim_length'])) {
$link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
$link_title = Unicode::truncate($link_title, $settings['trim_length'], FALSE, TRUE);
}
if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
......
......@@ -12,6 +12,7 @@
namespace Drupal\link\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldItemListInterface;
/**
......@@ -67,8 +68,8 @@ public function viewElements(FieldItemListInterface $items) {
}
$url_title = $url->toString();
if (!empty($settings['trim_length'])) {
$link_title = truncate_utf8($link_title, $settings['trim_length'], FALSE, TRUE);
$url_title = truncate_utf8($url_title, $settings['trim_length'], FALSE, TRUE);
$link_title = Unicode::truncate($link_title, $settings['trim_length'], FALSE, TRUE);
$url_title = Unicode::truncate($url_title, $settings['trim_length'], FALSE, TRUE);
}
$element[$delta] = array(
......
......@@ -8,6 +8,7 @@
namespace Drupal\link\Tests;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\link\LinkItemInterface;
use Drupal\simpletest\WebTestBase;
......@@ -384,11 +385,11 @@ function testLinkFormatter() {
switch ($setting) {
case 'trim_length':
$url = $url1;
$title = isset($new_value) ? truncate_utf8($title1, $new_value, FALSE, TRUE) : $title1;
$title = isset($new_value) ? Unicode::truncate($title1, $new_value, FALSE, TRUE) : $title1;
$this->assertRaw('<a href="' . String::checkPlain($url) . '">' . String::checkPlain($title) . '</a>');
$url = $url2;
$title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
$title = isset($new_value) ? Unicode::truncate($title2, $new_value, FALSE, TRUE) : $title2;
$this->assertRaw('<a href="' . String::checkPlain($url) . '">' . String::checkPlain($title) . '</a>');
break;
......@@ -503,15 +504,15 @@ function testLinkSeparateFormatter() {
switch ($setting) {
case 'trim_length':
$url = $url1;
$url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url;
$url_title = isset($new_value) ? Unicode::truncate($url, $new_value, FALSE, TRUE) : $url;
$expected = '<div class="link-item">';
$expected .= '<div class="link-url"><a href="' . String::checkPlain($url) . '">' . String::checkPlain($url_title) . '</a></div>';
$expected .= '</div>';
$this->assertRaw($expected);
$url = $url2;
$url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url;
$title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
$url_title = isset($new_value) ? Unicode::truncate($url, $new_value, FALSE, TRUE) : $url;
$title = isset($new_value) ? Unicode::truncate($title2, $new_value, FALSE, TRUE) : $title2;
$expected = '<div class="link-item">';
$expected .= '<div class="link-title">' . String::checkPlain($title) . '</div>';
$expected .= '<div class="link-url"><a href="' . String::checkPlain($url) . '">' . String::checkPlain($url_title) . '</a></div>';
......
......@@ -7,6 +7,7 @@
namespace Drupal\path\Controller;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Path\AliasStorageInterface;
use Drupal\Core\Path\AliasManagerInterface;
......@@ -85,10 +86,10 @@ public function adminOverview(Request $request) {
$destination = drupal_get_destination();
foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) {
$row = array();
$row['data']['alias'] = _l(truncate_utf8($data->alias, 50, FALSE, TRUE), $data->source, array(
$row['data']['alias'] = _l(Unicode::truncate($data->alias, 50, FALSE, TRUE), $data->source, array(
'attributes' => array('title' => $data->alias),
));
$row['data']['source'] = _l(truncate_utf8($data->source, 50, FALSE, TRUE), $data->source, array(
$row['data']['source'] = _l(Unicode::truncate($data->source, 50, FALSE, TRUE), $data->source, array(
'alias' => TRUE,
'attributes' => array('title' => $data->source),
));
......
......@@ -357,7 +357,7 @@ function _search_index_truncate(&$text) {
if (is_numeric($text)) {
$text = ltrim($text, '0');
}
$text = truncate_utf8($text, 50);
$text = Unicode::truncate($text, 50);
}
/**
......@@ -663,7 +663,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
// We didn't find any keyword matches, so just return the first part of the
// text. We also need to re-encode any HTML special characters that we
// entity-decoded above.
return String::checkPlain(truncate_utf8($text, 256, TRUE, TRUE));
return String::checkPlain(Unicode::truncate($text, 256, TRUE, TRUE));
}
// Sort the text ranges by starting position.
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -98,7 +99,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
// sentence boundaries.
// The summary may not be longer than maximum length specified. Initial slice.
$summary = truncate_utf8($text, $size);
$summary = Unicode::truncate($text, $size);
// Store the actual length of the UTF8 string -- which might not be the same
// as $size.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment