Add link action
authorMarcel Werk <burntime@woltlab.com>
Sat, 14 Dec 2024 13:40:22 +0000 (14:40 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 14 Dec 2024 13:40:22 +0000 (14:40 +0100)
wcfsetup/install/files/lib/system/gridView/action/EditAction.class.php
wcfsetup/install/files/lib/system/gridView/action/LinkAction.class.php [new file with mode: 0644]

index 73fae2c482a6deadb3ccfa79912efea6353b811c..277a07caffbc267c029cac85ab6e095ffa84dc56 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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 '<a href="' . $href . '">' . WCF::getLanguage()->get('wcf.global.button.edit') . '</a>';
-    }
-
-    #[\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 (file)
index 0000000..d2ce010
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+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;
+use wcf\util\StringUtil;
+
+/**
+ * Represents an action that links to a given controller.
+ *
+ * @author      Marcel Werk
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 '<a href="' . StringUtil::encodeHTML($href) . '">' . WCF::getLanguage()->get($this->languageItem) . '</a>';
+    }
+
+    #[\Override]
+    public function renderInitialization(AbstractGridView $gridView): ?string
+    {
+        return null;
+    }
+}