Skip to content

Commit

Permalink
Document admin dashboard boxes
Browse files Browse the repository at this point in the history
Closes #422
  • Loading branch information
BurntimeX committed Apr 30, 2024
1 parent 365f614 commit c04b57f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docs/php/api/acp_dashboard_boxes.md
Original file line number Diff line number Diff line change
@@ -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);
});
};
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c04b57f

Please sign in to comment.