From a56b8e32bcde435a94ebdba6dbae5e86119741a6 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 19 Nov 2024 16:16:07 +0100 Subject: [PATCH] Add renderer for truncated text --- .../TruncatedTextColumnRenderer.class.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/gridView/renderer/TruncatedTextColumnRenderer.class.php diff --git a/wcfsetup/install/files/lib/system/gridView/renderer/TruncatedTextColumnRenderer.class.php b/wcfsetup/install/files/lib/system/gridView/renderer/TruncatedTextColumnRenderer.class.php new file mode 100644 index 0000000000..e6299edb4b --- /dev/null +++ b/wcfsetup/install/files/lib/system/gridView/renderer/TruncatedTextColumnRenderer.class.php @@ -0,0 +1,33 @@ + + * @since 6.2 + */ +class TruncatedTextColumnRenderer extends DefaultColumnRenderer +{ + public function __construct( + private readonly int $length = 80, + private readonly string $etc = "\u{2026}" + ) {} + + #[\Override] + public function render(mixed $value, mixed $context = null): string + { + $renderedValue = StringUtil::encodeHTML(StringUtil::truncate($value, $this->length, $this->etc)); + + if (\mb_strlen($value) > $this->length) { + $renderedValue = '' . $renderedValue . ''; + } + + return $renderedValue; + } +} -- 2.20.1