---
url: /reference/plugin.md
description: >-
  Every fluent method on FilamentMediaLibraryPlugin: navigation, tenancy,
  metadata schema, access, the 17 feature flags and the default layout, sort and
  upload options.
---

# Plugin options

Register the plugin on each panel that should have a library. Every method returns the plugin, so you can chain them.

```php
use Hoceineel\FilamentMediaLibrary\Enums\BrowserLayout;
use Hoceineel\FilamentMediaLibrary\Enums\DuplicateStrategy;
use Hoceineel\FilamentMediaLibrary\Enums\Feature;
use Hoceineel\FilamentMediaLibrary\Enums\SortOrder;
use Hoceineel\FilamentMediaLibrary\FilamentMediaLibraryPlugin;
use Filament\Forms\Components\TextInput;

public function panel(Panel $panel): Panel
{
    return $panel
        ->id('admin')
        ->tenant(Team::class)
        ->plugin(
            FilamentMediaLibraryPlugin::make()
                ->navigationGroup('Content')
                ->navigationLabel('Assets')
                ->navigationIcon('heroicon-o-photo')
                ->navigationSort(20)
                ->navigationCountBadge()
                ->slug('assets')
                ->canAccess(fn (): bool => auth()->user()->isStaff())
                ->metadataSchema(fn (): array => [
                    TextInput::make('credit')->label('Photo credit'),
                    TextInput::make('license'),
                ])
                ->disableFeatures(Feature::UrlImport, Feature::AltText)
                ->defaultLayout(BrowserLayout::List)
                ->defaultSort(SortOrder::Newest)
                ->perPage(60)
                ->tileSize(200)
                ->acceptedFileTypes(['image/*', 'application/pdf'])
                ->maxFileSize(20 * 1024)
                ->duplicates(DuplicateStrategy::UseExisting),
        );
}
```

Fluent options apply to the panel they are registered on. They are copied into `config('filament-media-library.*')` when the panel boots, so they win over the config file. Outside panels no plugin runs: set the same values in [the config file](/reference/configuration).

## Static helpers

| Method | Returns |
|---|---|
| `FilamentMediaLibraryPlugin::make()` | A new plugin instance. |
| `FilamentMediaLibraryPlugin::get()` | The plugin registered on the current panel. |
| `FilamentMediaLibraryPlugin::isRegistered()` | `true` when the current panel has the plugin. |

## Page and navigation

| Method | Purpose |
|---|---|
| `page(string $page)` | Use your own page class. It must extend `MediaLibraryPage`. |
| `withoutPage(bool\|Closure $condition = true)` | Do not register the library page. Use the picker only. |
| `registerNavigation(bool\|Closure $condition = true)` | Show or hide the navigation item. |
| `navigationGroup(string\|Closure\|null $group)` | Navigation group. |
| `navigationLabel(string\|Closure\|null $label)` | Label. Defaults to the `navigation_label` translation. |
| `navigationIcon(string\|BackedEnum\|Closure\|null $icon)` | Icon. |
| `navigationSort(int\|Closure\|null $sort)` | Sort position. |
| `navigationCountBadge(bool\|Closure $condition = true)` | Show the file count as a badge. |
| `slug(?string $slug)` | Page URL slug. Defaults to `media-library`. |

## Tenancy

| Method | Purpose |
|---|---|
| `tenancy(bool $condition = true, bool $strict = true)` | Scope the library per tenant. On by default when the panel uses tenancy. With `strict`, a request without a tenant sees nothing. |
| `resolveTenantUsing(TenantResolver\|Closure\|string $resolver)` | Resolve the tenant yourself. Panels with tenancy use `FilamentTenantResolver` unless you set one. |

See [Multi-tenancy](/guide/tenancy).

## Inspector metadata

`metadataSchema(?Closure $schema)` adds fields to the inspector. Return an array of Filament form components. Values are stored in the item's `custom_properties`.

```php
->metadataSchema(fn (): array => [
    TextInput::make('credit'),
])
```

## Access

`canAccess(bool|Closure $condition)` hides the page and its navigation item and returns 403 when the condition is false. It does not replace the policies. See [Authorization](/reference/authorization).

## Features

Three methods control the `Feature` flags:

| Method | Behaviour |
|---|---|
| `features(array $features)` | Keep only the listed features and switch every other one off. |
| `enableFeatures(Feature ...$features)` | Switch the listed features on. |
| `disableFeatures(Feature ...$features)` | Switch the listed features off. |

```php
FilamentMediaLibraryPlugin::make()->features([Feature::Folders, Feature::Tags, Feature::Download]);
```

The `Hoceineel\FilamentMediaLibrary\Enums\Feature` enum has 17 cases:

| Case | Value | Switching it off removes |
|---|---|---|
| `Feature::Folders` | `folders` | The folder tree, folder breadcrumbs, new, rename, move and delete folder actions, and the folder field in the inspector. Everything lists at one level. |
| `Feature::Tags` | `tags` | The tag filter, tag field in the inspector and the bulk tag action. |
| `Feature::Favorites` | `favorites` | The favorite toggle and the Favorites view. |
| `Feature::Trash` | `trash` | The trash. Deleting removes files for good. |
| `Feature::PrivateMedia` | `private_media` | The private visibility option for files and folders. |
| `Feature::Versions` | `versions` | Version history and the restore action. |
| `Feature::ImageEditor` | `image_editor` | The crop, rotate and flip editor. |
| `Feature::FocalPoint` | `focal_point` | Setting the focal point. |
| `Feature::UrlImport` | `url_import` | Import from URL. |
| `Feature::FolderUpload` | `folder_upload` | Uploading a whole folder. |
| `Feature::AltText` | `alt_text` | The "Write it for me" alt text action. |
| `Feature::Duplicate` | `duplicate` | The duplicate action. |
| `Feature::Download` | `download` | Download buttons, including the bulk ZIP download. |
| `Feature::Exif` | `exif` | The camera data section in the inspector. |
| `Feature::Usage` | `usage` | The "Used in" section and the Unused view. |
| `Feature::SmartViews` | `smart_views` | The Recent, Favorites, Mine and Unused views. All files and Trash stay. |
| `Feature::KeyboardShortcuts` | `keyboard_shortcuts` | Keyboard shortcuts. See [Keyboard](/guide/keyboard). |

## Defaults

| Method | Config key | Notes |
|---|---|---|
| `defaultLayout(BrowserLayout $layout)` | `browser.default_layout` | `BrowserLayout::Grid` or `BrowserLayout::List`. |
| `defaultSort(SortOrder $sort)` | `browser.default_sort` | `Newest`, `Oldest`, `NameAsc`, `NameDesc`, `Largest`, `Smallest`. |
| `perPage(int $perPage)` | `browser.per_page` | Items per page. |
| `tileSize(int $pixels)` | `browser.tile_size` | Clamped between 120 and 280. |
| `acceptedFileTypes(array $mimeTypes)` | `upload.accepted_mime_types` | Wildcards such as `image/*` work. |
| `maxFileSize(int $kilobytes)` | `upload.max_file_size` | In kilobytes. |
| `duplicates(DuplicateStrategy $strategy)` | `upload.duplicates` | `Ask`, `Allow` or `UseExisting`. |

A [`MediaPicker`](/guide/picker-field) field has its own options for one field.
