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
Keep widgets lightweight - avoid heavy computations
Use caching for expensive operations
Handle empty data gracefully
Use translations for all text
Make responsive - test at different screen sizes
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), limitsuser(User entity): Current viewing userisAdminView(bool): Whether admin is viewingisOwner(bool): Whether current user is the server owner
ServerTabContext provides these methods:
hasPermission(string $permission): bool- Check if user has specific permissionhasAnyPermission(array $permissions): bool- Check if user has any of the permissionshasAllPermissions(array $permissions): bool- Check if user has all permissionsgetProductFeature(string $featureKey): mixed- Get product feature valuehasConfigurableStartup(): 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):
Related Guides
Event System - Subscribe to menu and tab events
Translations - Multi-language UI
Assets - Custom styles for widgets/tabs
Best Practices - Performance tips
Last updated