From 7a513a117e3b824b31a7e7e9521aa7a8f73aea9b Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sat, 14 Dec 2024 14:40:22 +0100 Subject: [PATCH] Add link action --- .../gridView/action/EditAction.class.php | 28 ++--------- .../gridView/action/LinkAction.class.php | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php diff --git a/wcfsetup/install/files/lib/system/gridView/action/EditAction.class.php b/wcfsetup/install/files/lib/system/gridView/action/EditAction.class.php index 73fae2c482..277a07caff 100644 --- a/wcfsetup/install/files/lib/system/gridView/action/EditAction.class.php +++ b/wcfsetup/install/files/lib/system/gridView/action/EditAction.class.php @@ -3,10 +3,6 @@ namespace wcf\system\gridView\action; use Closure; -use wcf\data\DatabaseObject; -use wcf\system\gridView\AbstractGridView; -use wcf\system\request\LinkHandler; -use wcf\system\WCF; /** * Represents an edit action. @@ -16,30 +12,12 @@ use wcf\system\WCF; * @license GNU Lesser General Public License * @since 6.2 */ -class EditAction extends AbstractAction +class EditAction extends LinkAction { public function __construct( - private readonly string $controllerClass, + string $controllerClass, ?Closure $isAvailableCallback = null ) { - parent::__construct($isAvailableCallback); - } - - #[\Override] - public function render(mixed $row): string - { - \assert($row instanceof DatabaseObject); - $href = LinkHandler::getInstance()->getControllerLink( - $this->controllerClass, - ['object' => $row] - ); - - return '' . WCF::getLanguage()->get('wcf.global.button.edit') . ''; - } - - #[\Override] - public function renderInitialization(AbstractGridView $gridView): ?string - { - return null; + parent::__construct($controllerClass, 'wcf.global.button.edit', $isAvailableCallback); } } diff --git a/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php b/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php new file mode 100644 index 0000000000..d2ce010f31 --- /dev/null +++ b/wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php @@ -0,0 +1,47 @@ + + * @since 6.2 + */ +class LinkAction extends AbstractAction +{ + public function __construct( + private readonly string $controllerClass, + private readonly string $languageItem, + ?Closure $isAvailableCallback = null + ) { + parent::__construct($isAvailableCallback); + } + + #[\Override] + public function render(mixed $row): string + { + \assert($row instanceof DatabaseObject); + $href = LinkHandler::getInstance()->getControllerLink( + $this->controllerClass, + ['object' => $row] + ); + + return '' . WCF::getLanguage()->get($this->languageItem) . ''; + } + + #[\Override] + public function renderInitialization(AbstractGridView $gridView): ?string + { + return null; + } +} -- 2.20.1