Document admin dashboard boxes
authorMarcel Werk <burntime@woltlab.com>
Tue, 30 Apr 2024 13:47:56 +0000 (15:47 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 30 Apr 2024 13:47:56 +0000 (15:47 +0200)
Closes #422

docs/php/api/acp_dashboard_boxes.md [new file with mode: 0644]
mkdocs.yml

diff --git a/docs/php/api/acp_dashboard_boxes.md b/docs/php/api/acp_dashboard_boxes.md
new file mode 100644 (file)
index 0000000..684020e
--- /dev/null
@@ -0,0 +1,55 @@
+# ACP Dashboard Boxes
+
+ACP Dashboard Boxes are displayed on the landing page of the admin panel and can provide the user with useful information. A box consists of an internal identifier, a name and the content of the box. The content can contain HTML code.
+
+## Create a Custom Box
+
+A custom box can be created with a custom PHP class that needs to implement the [`wcf\system\acp\dashboard\box\IAcpDashboardBox`](https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/system/acp/dashboard/box/IAcpDashboardBox.class.php) interface.
+It is recommended to extend the class [`wcf\system\acp\dashboard\box\AbstractAcpDashboardBox`](https://github.com/WoltLab/WCF/blob/master/wcfsetup/install/files/lib/system/acp/dashboard/box/AbstractAcpDashboardBox.class.php), which already provides a basic implementation of the interface.
+
+Example:
+
+```php
+<?php
+namespace wcf\system\acp\dashboard\box;
+
+use wcf\system\event\EventHandler;
+use wcf\system\acp\dashboard\event\AcpDashboardCollecting;
+
+final class FooBox extends AbstractAcpDashboardBox {
+    public function getTitle(): string
+    {
+        return 'title of the box';
+    }
+
+    public function getContent(): string
+    {
+        return 'content of the box';
+    }
+
+    public function getName(): string
+    {
+        return 'com.foo.bar'; // identifier of the box; must be unique
+    }
+}
+```
+
+## Register a Custom Box
+
+You can attach an event listener to the `wcf\system\acp\dashboard\event\AcpDashboardCollecting` event inside a bootstrap script to lazily register custom boxes.
+The class name of the box is registered using the event’s `register()` method:
+
+```php title="files/lib/bootstrap/com.example.bar.php"
+<?php
+
+use wcf\system\event\EventHandler;
+use wcf\system\acp\dashboard\event\AcpDashboardCollecting;
+
+return static function (): void {
+    $eventHandler = EventHandler::getInstance();
+
+    $eventHandler->register(AcpDashboardCollecting::class, static function (AcpDashboardCollecting $event) {
+        $event->register(\wcf\system\acp\dashboard\box\FooBox::class);
+    });
+};
+```
index e4f50a587cad69d0ff3bd1e9debfdf376fd02173..c6e01d59a4ed0e35d40a57cf1dcadc945ebe0a89 100644 (file)
@@ -24,6 +24,7 @@ nav:
       - 'Database Access': 'php/database-access.md'
       - 'Exceptions': 'php/exceptions.md'
       - 'API':
+          - 'ACP Dashboard Boxes': 'php/api/acp_dashboard_boxes.md'
           - 'Caches':
               - 'Overview': 'php/api/caches.md'
               - 'Persistent Caches': 'php/api/caches_persistent-caches.md'