diff --git a/README.md b/README.md index 6f170429..2ecd58f9 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ public function panel(Panel $panel): Panel ->navigationSort(3) ->navigationCountBadge() ->registerNavigation(false) + ->defaultView('grid' || 'list') ->resource(\App\Filament\Resources\CustomMediaResource::class) ]); } diff --git a/config/curator.php b/config/curator.php index 2a16162d..da996f6b 100644 --- a/config/curator.php +++ b/config/curator.php @@ -58,4 +58,7 @@ 'display_upload_new' => true, ], 'multi_select_key' => 'metaKey', + 'table' => [ + 'layout' => 'grid', + ] ]; diff --git a/src/CuratorPlugin.php b/src/CuratorPlugin.php index b41db143..2cae1dc1 100644 --- a/src/CuratorPlugin.php +++ b/src/CuratorPlugin.php @@ -24,6 +24,8 @@ class CuratorPlugin implements Plugin protected ?bool $shouldRegisterNavigation = null; + protected ?string $getDefaultListView = null; + protected string | Closure | null $pluralLabel = null; protected ?string $resource = null; @@ -40,7 +42,7 @@ public function register(Panel $panel): void $this->getResource(), ]); - if (! is_panel_auth_route()) { + if (!is_panel_auth_route()) { $panel ->renderHook( 'panels::body.end', @@ -103,6 +105,11 @@ public function shouldRegisterNavigation(): ?bool return $this->shouldRegisterNavigation ?? config('curator.should_register_navigation'); } + public function getDefaultListView(): ?string + { + return $this->getDefaultListView ?? config('curator.table.layout'); + } + public function navigationGroup(string | Closure | null $group = null): static { $this->navigationGroup = $group; @@ -138,6 +145,13 @@ public function registerNavigation(bool $show = true): static return $this; } + public function defaultView(string $view): static + { + $this->getDefaultListView = $view; + + return $this; + } + public function pluralLabel(string | Closure $label): static { $this->pluralLabel = $label; diff --git a/src/Resources/MediaResource/ListMedia.php b/src/Resources/MediaResource/ListMedia.php index 57f79b07..4cc2e968 100644 --- a/src/Resources/MediaResource/ListMedia.php +++ b/src/Resources/MediaResource/ListMedia.php @@ -12,7 +12,12 @@ class ListMedia extends ListRecords { - public string $layoutView = 'grid'; + public string $layoutView; + + public function boot() + { + $this->layoutView = CuratorPlugin::get()->getDefaultListView(); + } protected $listeners = [ 'changeLayoutView' => 'changeLayoutView',