Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

newbie360's avatar

Add a switch language dropdown but can we use enum in ActionGroup?

I'm new to Filament, and want to add a dropdown before the User Icon in the top right corner

i followed the doc register render hook, https://filamentphp.com/docs/3.x/support/render-hooks#registering-render-hooks

so i created a new service provider, and want to use the buildin dropdown ( https://filamentphp.com/docs/3.x/actions/grouping-actions#overview ), NOT a new blade component or blade view

use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Support\Facades\FilamentView;
use Filament\View\PanelsRenderHook;
use Illuminate\Support\ServiceProvider;

class FilamentServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        FilamentView::registerRenderHook(
            PanelsRenderHook::USER_MENU_BEFORE,
            function (): string {
                return ActionGroup::make([
                        //
                        // How to use enum here ?
                        //

                        //
                        // instead of this
                        //
                        Action::make('En'),
                        Action::make('ZhTw'),
                    ])
                    ->icon('heroicon-o-language')
                    ->tooltip(__('Switch Language'))
                    ->render();    // <------------ i called render() method here
            },
        );
    }
}

the dropdown working good, but how to use enum ? the ActionGroup::make() method accept array only

<?php

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

enum Language: string implements HasLabel
{
    case En = 'en';
    case ZhTw = 'zh_TW';

    const DEFAULT = self::En;

    const LABELS = [
        'En' => 'English',
        'ZhTw' => 'Traditional Chinese',
    ];

    public function getLabel(): ?string
    {
        return match ($this) {
            self::En => __(self::LABELS['En']),
            self::ZhTw => __(self::LABELS['ZhTw']),
        };
    }
}
0 likes
0 replies

Please or to participate in this conversation.