Allow usage of a grid view as a form node
authorMarcel Werk <burntime@woltlab.com>
Sat, 14 Dec 2024 13:40:13 +0000 (14:40 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 14 Dec 2024 13:40:13 +0000 (14:40 +0100)
wcfsetup/install/files/lib/system/form/builder/GridViewFormNode.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/form/builder/GridViewFormNode.class.php b/wcfsetup/install/files/lib/system/form/builder/GridViewFormNode.class.php
new file mode 100644 (file)
index 0000000..04f007b
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+namespace wcf\system\form\builder;
+
+use wcf\system\gridView\AbstractGridView;
+
+/**
+ * Form node that shows the contents of a grid view.
+ *
+ * @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 GridViewFormNode implements IFormChildNode
+{
+    use TFormChildNode;
+    use TFormNode;
+
+    protected AbstractGridView $gridView;
+
+    /**
+     * Returns the grid view object.
+     *
+     * @throws  \BadMethodCallException     if the grid view object has not been set yet
+     */
+    public function getGridView(): AbstractGridView
+    {
+        if (!isset($this->gridView)) {
+            throw new \BadMethodCallException(
+                "Grid view object has not been set yet for node '{$this->getId()}'."
+            );
+        }
+
+        return $this->gridView;
+    }
+
+    /**
+     * Sets the grid view object that contains the contents of the form node and returns this form node.
+     */
+    public function gridView(AbstractGridView $gridView): static
+    {
+        $this->gridView = $gridView;
+
+        return $this;
+    }
+
+    #[\Override]
+    public function getHtml()
+    {
+        return $this->getGridView()->render();
+    }
+
+    #[\Override]
+    public function validate()
+    {
+        // does nothing
+    }
+}