UI Components

Create custom widgets and server tabs to extend the PteroCA interface.

Dashboard Widgets

Widgets are UI components displayed on the dashboard or other contexts.

Widget Interface

<?php
namespace Plugins\MyPlugin\Widget;

use App\Core\Widget\WidgetContext;
use App\Core\Widget\WidgetInterface;
use App\Core\Widget\WidgetPosition;

class MyWidget implements WidgetInterface
{
    public function __construct(
        private readonly MyService $myService,
    ) {}

    public function getName(): string
    {
        return 'my_widget';
    }

    public function getDisplayName(): string
    {
        return 'My Custom Widget';
    }

    public function getSupportedContexts(): array
    {
        return [
            WidgetContext::DASHBOARD,      // Main dashboard
            WidgetContext::SERVER_DETAIL,  // Server detail page
        ];
    }

    public function getPosition(): WidgetPosition
    {
        return WidgetPosition::RIGHT;  // LEFT, CENTER, RIGHT
    }

    public function getPriority(): int
    {
        return 50;  // Higher = appears first (0-100)
    }

    public function getColumnSize(): int
    {
        return 12;  // Bootstrap grid: 1-12 (12 = full width)
    }

    public function getTemplate(): string
    {
        return '@PluginMyPlugin/widgets/my_widget.html.twig';
    }

    public function getData(WidgetContext $context, array $contextData): array
    {
        // Prepare data for template
        $data = $this->myService->getWidgetData();

        return [
            'items' => $data,
            'count' => count($data),
            'last_updated' => new \DateTimeImmutable(),
        ];
    }

    public function isVisible(WidgetContext $context, array $contextData): bool
    {
        // Control widget visibility
        // Example: only show to admins
        return $this->security->isGranted('ROLE_ADMIN');
    }
}

Widget Template

Registering Widgets

In Resources/config/services.yaml:

Important: Widgets MUST be tagged with widget.

Widget Contexts

  • DASHBOARD: Main dashboard page

  • SERVER_DETAIL: Individual server page

  • USER_PROFILE: User profile page

  • ADMIN_OVERVIEW: Admin overview page

Widget Positions

  • TOP: Top of the page

  • LEFT: Left column

  • RIGHT: Right column

  • BOTTOM: Bottom of the page

  • FULL_WIDTH: Full width across all columns

  • NAVBAR: Navigation bar area

Widget Best Practices

  1. Keep widgets lightweight - avoid heavy computations

  2. Use caching for expensive operations

  3. Handle empty data gracefully

  4. Use translations for all text

  5. Make responsive - test at different screen sizes

  6. Check permissions in isVisible()

Server Tabs

Add custom tabs to the server detail page.

Tab Interface

Tab Template

Templates receive the context variable which is a ServerTabContext object:

Context Data Available

ServerTabContext provides these public properties:

  • server (Server entity): Server object with id, name, game, pterodactylServerId, user (owner), etc.

  • serverData (ServerData DTO): Server status, isInstalling, resources (CPU, RAM, disk), limits

  • user (User entity): Current viewing user

  • isAdminView (bool): Whether admin is viewing

  • isOwner (bool): Whether current user is the server owner

ServerTabContext provides these methods:

  • hasPermission(string $permission): bool - Check if user has specific permission

  • hasAnyPermission(array $permissions): bool - Check if user has any of the permissions

  • hasAllPermissions(array $permissions): bool - Check if user has all permissions

  • getProductFeature(string $featureKey): mixed - Get product feature value

  • hasConfigurableStartup(): bool - Check if server has configurable startup

Access properties directly in PHP: $context->server->getId() Access in Twig templates: {{ context.server.id }}

Registering Tabs

Use an Event Subscriber (see Event System):

Last updated