Skip to Content
Module developmentInterface

Admin embedding

How a module adds a tab, badge or action to the player and server cards, a widget to the admin home, a setup checklist step and an announcement.

By the end your module's data sits where the owner already works: a tab on the player card, a button on the server card, a line on the admin home. The module needs no screen of its own for this, and when it is removed, its tabs and buttons go with it.

A tab on the player card

It is a class in the module's Surfaces/ folder with an attribute and a contract. There is nothing to register by hand: bootstrapModule() scans Surfaces/ on its own.

app/Modules/Example/Surfaces/PlayerReportsTab.php
<?php

declare(strict_types = 1);

namespace Flute\Modules\Example\Surfaces;

use Flute\Core\Database\Entities\Player;
use Flute\Core\Players\Contracts\PlayerTabProvider;
use Flute\Core\Players\Values\PlayerTab as Tab;
use Flute\Core\Surfaces\Attributes\PlayerTab;
use Flute\Modules\Example\Services\Reports;

#[PlayerTab(order: 60, permission: 'admin.example.view')]
final class PlayerReportsTab implements PlayerTabProvider
{
    public function __construct(
        private readonly Reports $reports,
    ) {
    }

    public function getTab(Player $player): ?Tab
    {
        return new Tab(
            id: 'example-reports',
            label: 'example-admin.player.tab',
            icon: 'sl.linear.flag',
            order: 60,
            group: Tab::GROUP_MODERATION,
            count: $this->reports->countAgainst($player),
        );
    }

    public function render(Player $player): mixed
    {
        return view('example::admin.player-reports', ['reports' => $this->reports->against($player)]);
    }
}

A server card tab works the same way: the #[ServerTab] attribute and the Flute\Core\Servers\Contracts\ServerTabProvider contract with getTab(Server $server): ?ServerTab and render(Server $server): mixed. The Votes module does this with its "Monitoring site votes" tab on the server card.

How it works

The attribute puts the class into SurfaceRegistry under its key, for example flute.player.tab. When the admin draws a card, it takes the classes of that key, skips those whose attribute permission the admin lacks, builds the rest through the container and calls the contract's methods. Constructor dependencies therefore work.

A getTab() that returns null hides the tab for that record. count is shown next to the name, 0 folds the tab away with the other empty ones, null means "not counted". Keep the count to one cheap query: it runs every time the card opens.

A player tab also shows on the public player page if its visibility allows it. The default is Audience::STAFF: staff only. Check is_admin_path() inside render() when the tab should look different on the site and in the admin.

Embedding points

The attributes live in Flute\Core\Surfaces\Attributes, and all take order: int = 0 and permission: ?string = null.

AttributeContractWhere it shows
#[PlayerTab]Players\Contracts\PlayerTabProvidera player card tab in the admin and on the site
#[PlayerBadge]Players\Contracts\PlayerHeaderBadge: provide(Player $player): ?Badgea badge in the player card header
#[PlayerCardLine]Players\Contracts\PlayerCardLine: provide(Player $player, ?User $viewer): ?CardLinea line on the player card outside the admin
#[PlayerQuickAction]Players\Contracts\PlayerQuickAction: getAction(Player, Actor): ?QuickAction, handle(Player, FluteRequest): mixedan action button for a player
#[PlayerColumn]Players\Contracts\PlayerListColumna column in the player list
#[ServerTab]Servers\Contracts\ServerTabProvidera server card tab
#[ServerBadge]Servers\Contracts\ServerHeaderBadge: provide(Server $server): ?Badgea badge in the server card header
#[ServerQuickAction]Servers\Contracts\ServerQuickActionan action button for a server; handle() runs only for someone allowed to manage the server

Badge(id, label, tone, icon, severity, visibility, details), tones Badge::TONE_NEUTRAL, TONE_SUCCESS, TONE_WARNING, TONE_DANGER. QuickAction(id, label, icon, variant, confirm, order, url, fragment, fields, elevated, visibility, bulk, confirmText, secondary, place): elevated: true asks the viewer to confirm their login again, place: QuickAction::PLACE_ADMIN keeps the button in the admin only. The core's other embedding points are listed in app/Core/AGENTS.md.

Admin home

A home widget comes from a Flute\Admin\UI\Home\Contracts\HomeWidgetProvider. Register it in the admin package's initialize(): app(HomeProviderRegistry::class)->register(new ExampleHome()).

app/Modules/Example/Admin/Home/ExampleHome.php
<?php

declare(strict_types = 1);

namespace Flute\Modules\Example\Admin\Home;

use Flute\Admin\UI\Home\Contracts\HomeWidgetProvider;
use Flute\Admin\UI\Home\HomeActor;
use Flute\Admin\UI\Home\HomeWidget;
use Flute\Admin\UI\Schema\Component;
use Flute\Modules\Example\Services\Reports;

final class ExampleHome implements HomeWidgetProvider
{
    public function widgets(HomeActor $actor): array
    {
        return [
            HomeWidget::stat(
                'example.open',
                'admin.example.view',
                50,
                static fn(): bool => app(Reports::class)->openCount() > 0,
                static fn(): Component => Component::make('stat-cell', 'home-stat-example')->props([
                    'label' => 'example-admin.home.open',
                    'value' => (string) app(Reports::class)->openCount(),
                ]),
            ),
        ];
    }
}

The arguments are id, permission, priority, a show condition (or null) and a closure that builds the component. The closure runs only when the permission is held and the condition passes. Slots: HomeWidget::stat() (the numbers on top), attention() (what waits for a person), action(), feed(), and HomeWidget::for(HomeWidget::SLOT_HERO, ...) for a link above the greeting. The Giveaways module puts the number of running giveaways among the numbers and a giveaway that is due for its draw under attention.

Setup checklist step

A step in the home's "Community setup" list is added through Flute\Admin\UI\Home\Setup\SetupChecklist and described by Flute\Admin\UI\Home\Setup\SetupStep. The done mark comes from a check over real data; nobody ticks it by hand.

app/Modules/Example/Providers/ExampleProvider.php
public function bootRequest(Container $container): void
{
    if (is_admin_path()) {
        $container->get(SetupChecklist::class)->register(new SetupStep(
            key: 'example.first_category',
            title: 'example-admin.setup.title',
            description: 'example-admin.setup.desc',
            href: '/admin/example',
            permission: 'admin.example',
            done: static fn(): bool => Category::query()->count() > 0,
            minutes: 2,
            order: 40,
        ));
    }
}

href is an admin path, or surface:<id> to open a modal window. A done step is cached for a day, a pending one is checked again after a minute. The SampKit module does this: its plugin step is marked done once a SA-MP server has connected.

Screen announcement

A window with an explanation that each admin sees once is registered in Flute\Admin\UI\Onboarding\AnnouncementRegistry from the package's initialize(), and described by Flute\Admin\UI\Onboarding\Announcement:

app(AnnouncementRegistry::class)->register(new Announcement(
    id: 'example.page.reports',
    slides: [['title' => 'example-admin.intro.title', 'text' => 'example-admin.intro.text']],
    permission: 'admin.example',
    routes: ['/admin/example'],
    primary: ['label' => 'admin-onboarding.got_it'],
));

routes are the addresses the window opens on (prefix match); an empty list means any admin page. since: '2.1.0' shows the window only once the engine is at that version. At most one announcement opens per page load.

Common mistakes

The tab does not show up. The class is not in Surfaces/, its namespace is not Flute\Modules\<Name>\Surfaces, or the folder list is cached outside debug mode: run php flute cache:clear.

Some attributes share a name with a class you also need (PlayerTab, PlayerCardLine). Import one of them under another name, as in the example.

A heavy count or query in getTab() slows down every card. Count with one query and load the body's data in render().

Learn more

On this page