-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from WoltLab/acp-dashboard-boxes
Document admin dashboard boxes
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters