Filament Plugins

Purchase

Extending

Sometimes you need more control over the Media Library page than the plugin's configuration methods provide – for example, to add header widgets, override footer actions, or use Filament's full page API for something project-specific. The cleanest way to do this is to subclass the page and register your custom class with the plugin.

Creating a subclass

Create a new page class that extends RalphJSmit\Filament\MediaLibrary\Filament\Pages\MediaLibrary:

app/Filament/Pages/MediaLibraryPage.php
<?php

namespace App\Filament\Pages;

use RalphJSmit\Filament\MediaLibrary\Filament\Pages\MediaLibrary;

class MediaLibraryPage extends MediaLibrary
{
    protected function getHeaderWidgets(): array
    {
        return [
            // Your custom header widgets here
        ];
    }
}

Registering the subclass

Next, open up your panel provider and pass the class to ->mediaLibraryPage() on the plugin:

app/Providers/Filament/AdminPanelProvider.php
use App\Filament\Pages\MediaLibraryPage;
use RalphJSmit\Filament\MediaLibrary\FilamentMediaLibrary;

$panel->plugin(
    FilamentMediaLibrary::make()
        ->mediaLibraryPage(MediaLibraryPage::class),
);

That's all the wiring you need – the plugin will register your class instead of the default page.

Changing the file click behavior

To change the file click behavior, you don't need a subclass – set it on the plugin as documented in File click behavior. However, if you need to resolve the behavior dynamically (for example, per user), you can override the getFileClickBehavior() method in your subclass. The override takes precedence over the plugin option:

app/Filament/Pages/MediaLibraryPage.php
use RalphJSmit\Filament\Explore\Filament\Schemas\Components\File\FileClickBehavior;

protected function getFileClickBehavior(): FileClickBehavior
{
    return FileClickBehavior::View;
}

The same option is available on the MediaPicker field as well – see Viewing files without selecting them.

Your subclass already includes the HasPageConfiguration trait from the base page. This trait proxies every navigation and configuration call – ->navigationLabel(), ->navigationGroup(), ->navigationIcon(), ->slug(), and so on – through the plugin instance. You don't need to redeclare any of those in your subclass; anything you set on the plugin in your panel provider continues to work exactly as documented in the Navigation page.

If you override a static method like getNavigationIcon() or getNavigationLabel() directly in your subclass, that value will take precedence over whatever the plugin has configured, so only do that intentionally.

© FilamentPlugins.com ✦ 2022 – 2026
PrivacyTerms & Conditions
All rights reserved.