diff --git a/core/modules/rest/src/Plugin/views/display/RestExport.php b/core/modules/rest/src/Plugin/views/display/RestExport.php index b3733e4ec87e3d9fcdbc89e79742eb2549237f4c..063f983e547d2a59b2f61dcb73570017ba9946d3 100644 --- a/core/modules/rest/src/Plugin/views/display/RestExport.php +++ b/core/modules/rest/src/Plugin/views/display/RestExport.php @@ -2,6 +2,7 @@ namespace Drupal\rest\Plugin\views\display; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheableResponse; use Drupal\Core\Form\FormStateInterface; @@ -296,7 +297,7 @@ public function optionsSummary(&$categories, &$options) { $options['auth'] = [ 'category' => 'path', 'title' => $this->t('Authentication'), - 'value' => views_ui_truncate($auth, 24), + 'value' => Unicode::truncate($auth, 24, FALSE, TRUE), ]; // Remove css/exposed form settings, as they are not used for the data diff --git a/core/modules/views/src/Plugin/views/display/Block.php b/core/modules/views/src/Plugin/views/display/Block.php index 00bdf1a10b843513843b988f09a623811860802f..423f2a944c2bb43c42a2adc51ee8ceb416c787b3 100644 --- a/core/modules/views/src/Plugin/views/display/Block.php +++ b/core/modules/views/src/Plugin/views/display/Block.php @@ -2,6 +2,7 @@ namespace Drupal\views\Plugin\views\display; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Url; use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface; use Drupal\Core\Block\BlockManagerInterface; @@ -162,12 +163,12 @@ public function optionsSummary(&$categories, &$options) { $options['block_description'] = [ 'category' => 'block', 'title' => $this->t('Block name'), - 'value' => views_ui_truncate($block_description, 24), + 'value' => Unicode::truncate($block_description, 24, FALSE, TRUE), ]; $options['block_category'] = [ 'category' => 'block', 'title' => $this->t('Block category'), - 'value' => views_ui_truncate($block_category, 24), + 'value' => Unicode::truncate($block_category, 24, FALSE, TRUE), ]; $filtered_allow = array_filter($this->getOption('allow')); diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index ef24bb6eee649d0994c9e751152bffcb7ac4369e..81c37a2c37dc5d3dba33ab8e6f74d79a4c3f3059 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Utility\Html; use Drupal\Component\Render\FormattableMarkup; +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; @@ -1119,7 +1120,7 @@ public function optionsSummary(&$categories, &$options) { ]; } - $display_comment = views_ui_truncate($this->getOption('display_comment'), 80); + $display_comment = Unicode::truncate($this->getOption('display_comment'), 80, TRUE, TRUE); $options['display_comment'] = [ 'category' => 'other', 'title' => $this->t('Administrative comment'), @@ -1135,7 +1136,7 @@ public function optionsSummary(&$categories, &$options) { $options['title'] = [ 'category' => 'title', 'title' => $this->t('Title'), - 'value' => views_ui_truncate($title, 32), + 'value' => Unicode::truncate($title, 32, FALSE, TRUE), 'desc' => $this->t('Change the title that this display will use.'), ]; diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 19f129148dbdd15e914c9fa93723b5704ec6e2b0..bf0286ffa6cc867a7e86b92ea530da44d3e73a10 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -2,6 +2,7 @@ namespace Drupal\views\Plugin\views\display; +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormStateInterface; @@ -239,7 +240,7 @@ public function optionsSummary(&$categories, &$options) { $options['menu'] = [ 'category' => 'page', 'title' => $this->t('Menu'), - 'value' => views_ui_truncate($menu_str, 24), + 'value' => Unicode::truncate($menu_str, 24, FALSE, TRUE), ]; // This adds a 'Settings' link to the style_options setting if the style diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 438c2095412df29d38934c85a691186d807e2121..984d740e57bc50df7415162a1adb56a77bc0c9fd 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -2,6 +2,7 @@ namespace Drupal\views\Plugin\views\display; +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -426,7 +427,7 @@ public function optionsSummary(&$categories, &$options) { $options['path'] = [ 'category' => 'page', 'title' => $this->t('Path'), - 'value' => views_ui_truncate($path, 24), + 'value' => Unicode::truncate($path, 24, FALSE, TRUE), ]; } diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php index 0ff2ba81f1ae83f359e4c3455c83339c1037d6aa..3c4b41d5cd1a99502d873501a97c6b7a9cef89a6 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php @@ -2,6 +2,7 @@ namespace Drupal\views_test_data\Plugin\views\display; +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -63,7 +64,7 @@ public function optionsSummary(&$categories, &$options) { $options['test_option'] = [ 'category' => 'display_test', 'title' => $this->t('Test option'), - 'value' => views_ui_truncate($test_option, 24), + 'value' => Unicode::truncate($test_option, 24, FALSE, TRUE), ]; } diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php index 25594c3584a3502dcfe6abd1838eec688aad3b13..ff08fa4e933989599e894ea16f307c7a55c5bc4f 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display_extender/DisplayExtenderTest.php @@ -2,6 +2,7 @@ namespace Drupal\views_test_data\Plugin\views\display_extender; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Plugin\views\display_extender\DisplayExtenderPluginBase; @@ -50,7 +51,7 @@ public function optionsSummary(&$categories, &$options) { $options['test_extender_test_option'] = [ 'category' => 'display_extender_test', 'title' => $this->t('Test option'), - 'value' => views_ui_truncate($this->options['test_extender_test_option'], 24), + 'value' => Unicode::truncate($this->options['test_extender_test_option'], 24, FALSE, TRUE), ]; } diff --git a/core/modules/views_ui/src/ViewFormBase.php b/core/modules/views_ui/src/ViewFormBase.php index c04628bfdabc9a660c95cc8af1c2b947f37dbfe3..67a71bdd55228a06f200f8ccccc51c4becc60e17 100644 --- a/core/modules/views_ui/src/ViewFormBase.php +++ b/core/modules/views_ui/src/ViewFormBase.php @@ -2,6 +2,7 @@ namespace Drupal\views_ui; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -160,7 +161,7 @@ public function isDefaultDisplayShown(ViewUI $view) { public function getDisplayLabel(ViewUI $view, $display_id, $check_changed = TRUE) { $display = $view->get('display'); $title = $display_id == 'default' ? $this->t('Default') : $display[$display_id]['display_title']; - $title = views_ui_truncate($title, 25); + $title = Unicode::truncate($title, 25, FALSE, TRUE); if ($check_changed && !empty($view->changed_display[$display_id])) { $changed = '*'; diff --git a/core/modules/views_ui/tests/src/Functional/DisplayTest.php b/core/modules/views_ui/tests/src/Functional/DisplayTest.php index ae46f6abf2ca34cd32fe65da85f1022ee908abae..8d10c8c8f878a8b44dfcfa7f0ed09e8c37c9afc3 100644 --- a/core/modules/views_ui/tests/src/Functional/DisplayTest.php +++ b/core/modules/views_ui/tests/src/Functional/DisplayTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\Functional; +use Drupal\Component\Utility\Unicode; use Drupal\views\Entity\View; use Drupal\views\Views; @@ -227,7 +228,7 @@ public function testDisplayTitleInButtonsXss() { $view->save(); $this->drupalGet("admin/structure/views/view/{$view->id()}"); - $escaped = views_ui_truncate($input, 25); + $escaped = Unicode::truncate($input, 25, FALSE, TRUE); $this->assertSession()->assertEscaped($escaped); $this->assertSession()->responseNotContains($xss_markup); diff --git a/core/modules/views_ui/tests/src/Functional/ViewEditTest.php b/core/modules/views_ui/tests/src/Functional/ViewEditTest.php index 722a2a332c668b2ad6bd937408af9d94d0f31220..6d957f6f14e7727bb3434b2288ad27a955fa6504 100644 --- a/core/modules/views_ui/tests/src/Functional/ViewEditTest.php +++ b/core/modules/views_ui/tests/src/Functional/ViewEditTest.php @@ -50,12 +50,11 @@ public function testOtherOptions() { $this->drupalGet('admin/structure/views/view/test_view'); // Add a new attachment display. $this->submitForm([], 'Add Attachment'); - // Test that a long administrative comment is truncated. $edit = ['display_comment' => 'one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen']; $this->drupalGet('admin/structure/views/nojs/display/test_view/attachment_1/display_comment'); $this->submitForm($edit, 'Apply'); - $this->assertSession()->pageTextContains('one two three four five six seven eight nine ten eleven twelve thirteen fourteen...'); + $this->assertSession()->pageTextContains('one two three four five six seven eight nine ten eleven twelve thirteen…'); // Change the machine name for the display from page_1 to test_1. $edit = ['display_id' => 'test_1']; diff --git a/core/modules/views_ui/tests/src/Functional/WizardTest.php b/core/modules/views_ui/tests/src/Functional/WizardTest.php index 81718fd21c46981892362bf7da95ac1ec3616a79..95378286c47ffe5f631b259a735bfe0f729c3421 100644 --- a/core/modules/views_ui/tests/src/Functional/WizardTest.php +++ b/core/modules/views_ui/tests/src/Functional/WizardTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\Functional; +use Drupal\Component\Utility\Unicode; use Drupal\Tests\views\Functional\Wizard\WizardTestBase; /** @@ -65,7 +66,7 @@ public function testWizardFieldLength() { $this->submitForm($view, 'Save and edit'); $this->assertSession()->addressEquals('admin/structure/views/view/' . $view['id']); // Assert that the page title is correctly truncated. - $this->assertSession()->pageTextContains(views_ui_truncate($view['page[title]'], 32)); + $this->assertSession()->pageTextContains(Unicode::truncate($view['page[title]'], 32, FALSE, TRUE)); } } diff --git a/core/modules/views_ui/tests/src/Kernel/TruncateDeprecateTest.php b/core/modules/views_ui/tests/src/Kernel/TruncateDeprecateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..754445ad5b92cc6acfd32b9f8e5612cd41ff9659 --- /dev/null +++ b/core/modules/views_ui/tests/src/Kernel/TruncateDeprecateTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Drupal\Tests\views_ui\Kernel; + +use Drupal\Tests\views\Kernel\ViewsKernelTestBase; + +/** + * Tests the deprecation of views_ui_truncate() function. + * + * @group views_ui + */ +class TruncateDeprecateTest extends ViewsKernelTestBase { + + /** + * Modules to enable. + * + * @var array + */ + protected static $modules = ['views', 'views_ui']; + + /** + * Tests the deprecation of views_ui_truncate() replaced by Unicode::truncate. + * + * @group legacy + */ + public function testDeprecateViewsUiTruncate() { + $string = 'one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen'; + $short_string = views_ui_truncate($string, 80); + $this->expectDeprecation('views_ui_truncate() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Component\Utility\Unicode::truncate(). See https://www.drupal.org/node/3408283'); + } + +} diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 33dbb6b3c65f74dd12cb0f3a16679907efa5700d..0598b2d142e3cc268bfce6d631098dea8856f883 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -5,6 +5,7 @@ * Provide structure for the administrative interface to Views. */ +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; @@ -339,12 +340,13 @@ function views_ui_views_analyze(ViewExecutable $view) { * Truncate strings to a set length and provide a '...' if they truncated. * * This is often used in the UI to ensure long strings fit. + * + * @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. + * Use \Drupal\Component\Utility\Unicode::truncate(). + * + * @see https://www.drupal.org/node/3408283 */ function views_ui_truncate($string, $length) { - if (mb_strlen($string) > $length) { - $string = mb_substr($string, 0, $length); - $string .= '...'; - } - - return $string; + @trigger_error('views_ui_truncate() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use \Drupal\Component\Utility\Unicode::truncate(). See https://www.drupal.org/node/3408283', E_USER_DEPRECATED); + return Unicode::truncate($string, $length, FALSE, TRUE); }