Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document API to configure ACP menu items via bootstrap script #430

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/migration/wsc60/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ class MyForm extends AbstractForm {
## RSS Feeds

A [new API](../../php/api/rss_feeds.md) for the output of content as an RSS feed has been introduced.

## ACP Menu Items

A [new API](../../package/acp-menu-items.md) for adding ACP menu items has been introduced. The previous option of adding menu entries via PIP is still supported, but is to be discontinued in the long term.
46 changes: 46 additions & 0 deletions docs/package/acp-menu-items.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ACP Menu Items

The API for the ACP menu items allows you to add your own menu items in the admin panel with your package.
BurntimeX marked this conversation as resolved.
Show resolved Hide resolved

Since WoltLab Suite 6.1 you can attach an event listener to the `wcf\system\menu\acp\event\AcpMenuCollecting` event inside a bootstrap script to lazily register your ACP menu items.

The `register` method of the event expects an object of the type `wcf\system\menu\acp\AcpMenuItem` as a parameter. An `AcpMenuItem` object consists of the following parameters:

| Name | Type | Description |
|------|------|-------------|
| `$menuItem` | string | Identifier of the item; must be unique |
| `$title` | string | (Optional) title of the item; if omitted `$menuItem` is used as language variable |
| `$parentMenuItem` | string | (Optional) identifier of the parent item |
| `$link` | string | (Optional) URL of the linked page |
| `$icon` | string | (Optional) icon of the item |

Example:

```php
<?php

use wcf\system\event\EventHandler;
use wcf\system\menu\acp\AcpMenuItem;
use wcf\system\menu\acp\event\AcpMenuCollecting;
use wcf\system\request\LinkHandler;

return static function (): void {
EventHandler::getInstance()->register(AcpMenuCollecting::class, static function (AcpMenuCollecting $event) {
$event->register(new AcpMenuItem(
"com.woltlab.foor.bar",
'Example Title',
'wcf.acp.menu.link.application'
));

if (true) {
BurntimeX marked this conversation as resolved.
Show resolved Hide resolved
$event->register(new AcpMenuItem(
"com.woltlab.foor.bar.add",
'Example Add Title',
"com.woltlab.foor.bar",
LinkHandler::getInstance()->getControllerLink(FooAddForm::class),
'plus;false'
BurntimeX marked this conversation as resolved.
Show resolved Hide resolved
));
}
});
};
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ nav:
- 'userNotificationEvent': 'package/pip/user-notification-event.md'
- 'userOption': 'package/pip/user-option.md'
- 'userProfileMenu': 'package/pip/user-profile-menu.md'
- 'ACP Menu Items': 'package/acp-menu-items.md'
- 'Database PHP API': 'package/database-php-api.md'

- 'Migration':
Expand Down
Loading