2026-06-01 10:10:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Bjanczak\FilamentShortUrl;
|
|
|
|
|
|
|
|
|
|
use Bjanczak\FilamentShortUrl\Filament\Resources\ShortUrlResource;
|
|
|
|
|
use Filament\Contracts\Plugin;
|
|
|
|
|
use Filament\Panel;
|
|
|
|
|
|
|
|
|
|
class FilamentShortUrlPlugin implements Plugin
|
|
|
|
|
{
|
|
|
|
|
protected ?string $navigationGroup = null;
|
|
|
|
|
|
|
|
|
|
protected ?int $navigationSort = null;
|
|
|
|
|
|
2026-06-01 10:27:02 +02:00
|
|
|
protected ?string $navigationLabel = null;
|
|
|
|
|
|
|
|
|
|
protected ?string $navigationIcon = null;
|
|
|
|
|
|
2026-06-01 10:10:26 +02:00
|
|
|
protected ?string $routePrefix = null;
|
|
|
|
|
|
|
|
|
|
// ─── Factory ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
public static function make(): static
|
|
|
|
|
{
|
|
|
|
|
return app(static::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function get(): static
|
|
|
|
|
{
|
|
|
|
|
return filament(app(static::class)->getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Plugin interface ────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
public function getId(): string
|
|
|
|
|
{
|
|
|
|
|
return 'filament-short-url';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function register(Panel $panel): void
|
|
|
|
|
{
|
|
|
|
|
$panel
|
|
|
|
|
->resources([
|
|
|
|
|
ShortUrlResource::class,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(Panel $panel): void
|
|
|
|
|
{
|
|
|
|
|
// Configuration is consumed by ShortUrlResource via FilamentShortUrlPlugin::get()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Fluent configuration API ────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the navigation group for the Short URLs resource.
|
|
|
|
|
*
|
|
|
|
|
* @example FilamentShortUrlPlugin::make()->navigationGroup('Marketing')
|
|
|
|
|
*/
|
|
|
|
|
public function navigationGroup(string $group): static
|
|
|
|
|
{
|
|
|
|
|
$this->navigationGroup = $group;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getNavigationGroup(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->navigationGroup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the navigation sort order.
|
2026-06-01 10:27:02 +02:00
|
|
|
*
|
|
|
|
|
* @example FilamentShortUrlPlugin::make()->navigationSort(50)
|
2026-06-01 10:10:26 +02:00
|
|
|
*/
|
|
|
|
|
public function navigationSort(int $sort): static
|
|
|
|
|
{
|
|
|
|
|
$this->navigationSort = $sort;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getNavigationSort(): ?int
|
|
|
|
|
{
|
|
|
|
|
return $this->navigationSort;
|
|
|
|
|
}
|
2026-06-01 10:27:02 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Override the navigation label (menu item name).
|
|
|
|
|
*
|
|
|
|
|
* @example FilamentShortUrlPlugin::make()->navigationLabel('Short Links')
|
|
|
|
|
*/
|
|
|
|
|
public function navigationLabel(string $label): static
|
|
|
|
|
{
|
|
|
|
|
$this->navigationLabel = $label;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getNavigationLabel(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->navigationLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Override the navigation icon.
|
|
|
|
|
*
|
|
|
|
|
* @example FilamentShortUrlPlugin::make()->navigationIcon('heroicon-o-link')
|
|
|
|
|
*/
|
|
|
|
|
public function navigationIcon(string $icon): static
|
|
|
|
|
{
|
|
|
|
|
$this->navigationIcon = $icon;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getNavigationIcon(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->navigationIcon;
|
|
|
|
|
}
|
2026-06-01 10:10:26 +02:00
|
|
|
}
|