From 5bd73f13a5d098a0e3ea84769b8f9c772dc2bc23 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 17 Dec 2024 14:30:36 +0100 Subject: [PATCH] Allow dynamic language items for action labels --- .../gridView/action/AbstractAction.class.php | 9 ++++++++- .../system/gridView/action/LinkAction.class.php | 16 ++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/system/gridView/action/AbstractAction.class.php b/wcfsetup/install/files/lib/system/gridView/action/AbstractAction.class.php index e975908d53..776b167648 100644 --- a/wcfsetup/install/files/lib/system/gridView/action/AbstractAction.class.php +++ b/wcfsetup/install/files/lib/system/gridView/action/AbstractAction.class.php @@ -3,6 +3,7 @@ namespace wcf\system\gridView\action; use Closure; +use wcf\system\gridView\AbstractGridView; /** * Provides an abstract implementation of a grid view action. @@ -15,7 +16,7 @@ use Closure; abstract class AbstractAction implements IGridViewAction { public function __construct( - private readonly ?Closure $isAvailableCallback = null + protected readonly ?Closure $isAvailableCallback = null ) {} #[\Override] @@ -33,4 +34,10 @@ abstract class AbstractAction implements IGridViewAction { return false; } + + #[\Override] + public function renderInitialization(AbstractGridView $gridView): ?string + { + return null; + } } diff --git a/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php b/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php index d2ce010f31..2173117e1f 100644 --- a/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php +++ b/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php @@ -20,8 +20,8 @@ use wcf\util\StringUtil; class LinkAction extends AbstractAction { public function __construct( - private readonly string $controllerClass, - private readonly string $languageItem, + protected readonly string $controllerClass, + protected readonly string|Closure $languageItem, ?Closure $isAvailableCallback = null ) { parent::__construct($isAvailableCallback); @@ -36,12 +36,12 @@ class LinkAction extends AbstractAction ['object' => $row] ); - return '' . WCF::getLanguage()->get($this->languageItem) . ''; - } + if (\is_string($this->languageItem)) { + $title = WCF::getLanguage()->get($this->languageItem); + } else { + $title = ($this->languageItem)($row); + } - #[\Override] - public function renderInitialization(AbstractGridView $gridView): ?string - { - return null; + return \sprintf('%s', StringUtil::encodeHTML($href), $title); } } -- 2.20.1