Skip to content

Commit 8359eba

Browse files
committed
Merge branch 'main' of github.com:statikbe/laravel-filament-flexible-blocks-asset-manager
2 parents eb50023 + ddde462 commit 8359eba

13 files changed

+95
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-filament-flexible-blocks-asset-manager` will be documented in this file.
44

5+
## v1.0.0 - 2024-10-09
6+
7+
First version of the asset manager
8+
59
## 1.0.0 - 202X-XX-XX
610

711
- initial release

config/filament-flexible-blocks-asset-manager.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
// config for Statik/FilamentFlexibleBlocksAssetManager
4+
45
return [
56
/*
67
|--------------------------------------------------------------------------
@@ -21,6 +22,16 @@
2122
*/
2223
'navigation_group' => null,
2324

25+
/*
26+
|--------------------------------------------------------------------------
27+
| Model & Resource
28+
|--------------------------------------------------------------------------
29+
|
30+
| You can override the model and resource that are used. Be sure to inherit from our defaults.
31+
*/
32+
'model' => \Statikbe\FilamentFlexibleBlocksAssetManager\Models\Asset::class,
33+
'resource' => \Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource::class,
34+
2435
/*
2536
|--------------------------------------------------------------------------
2637
| Image editor
@@ -90,15 +101,20 @@
90101
| Asset authorisation
91102
|--------------------------------------------------------------------------
92103
|
93-
| The assets URLs can be protected. This can be done in different ways:
94-
| 1. a gate, see https://laravel.com/docs/11.x/authorization#gates
95-
| You can define a gate that takes the asset record as argument.
96-
| 2. a policy, see https://laravel.com/docs/11.x/authorization#writing-policies
97-
| You can write a policy for the Asset model. The `view` policy will be used to authorise.
104+
| The assets URLs can be protected and access to the Filament can be configured.
105+
| You need to define a new model policy and add an extra function for the public
106+
| file access of the asset. The name of this function needs to be added to the key
107+
| 'gate'. The policy class needs to be added to the key 'policy'.
108+
| The middleware is only used for assets URLs. You can get the assetId in the middleware by
109+
| calling $request->route('assetId')
110+
|
111+
| see https://laravel.com/docs/11.x/authorization#gates and
112+
| https://laravel.com/docs/11.x/authorization#writing-policies
98113
*/
99114
'asset_authorisation' => [
100115
//'gate' => 'asset-access',
101116
//'policy' => AssetPolicy::class,
117+
//'middleware' => AssetRedirectMiddleware::class,
102118
],
103119

104120
/*

routes/filament-flexible-blocks-asset-manager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
66
use Statikbe\FilamentFlexibleBlocksAssetManager\Http\Controllers\AssetController;
77

8+
$assetMiddleware = FilamentFlexibleBlocksAssetManagerConfig::getAssetMiddleware();
89
$assetRoutePrefix = FilamentFlexibleBlocksAssetManagerConfig::getAssetRoutePrefix();
910
$assetRoutePrefix = Str::replaceEnd('/', '', $assetRoutePrefix);
1011

11-
Route::get("$assetRoutePrefix/{asset}/{locale?}", [AssetController::class, 'index'])
12-
->middleware(['web'])
12+
Route::get("$assetRoutePrefix/{assetId}/{locale?}", [AssetController::class, 'index'])
13+
->middleware(['web', $assetMiddleware ?? ''])
1314
->name('filament-flexible-blocks-asset-manager.asset_index');

src/Filament/Form/Fields/Blocks/Type/AssetCallToActionType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Form\Fields\Blocks\Type;
44

5+
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
56
use Statikbe\FilamentFlexibleBlocksAssetManager\Models\Asset;
67
use Statikbe\FilamentFlexibleContentBlocks\Filament\Form\Fields\Blocks\Type\CallToActionType;
78

@@ -12,7 +13,7 @@ protected function setUp(): void
1213
parent::setUp();
1314

1415
$this->titleColumnName('name');
15-
$this->model(Asset::class);
16+
$this->model(FilamentFlexibleBlocksAssetManagerConfig::getModel());
1617
$this->label(trans('filament-flexible-blocks-asset-manager::filament-flexible-blocks-asset-manager.asset_lbl'));
1718

1819
$this->searchColumns(['name']);

src/Filament/Resources/AssetResource.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
use Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource\Pages\EditAsset;
1616
use Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource\Pages\ListAssets;
1717
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
18-
use Statikbe\FilamentFlexibleBlocksAssetManager\Models\Asset;
1918

2019
class AssetResource extends Resource
2120
{
2221
use Translatable;
2322

24-
protected static ?string $model = Asset::class;
25-
2623
protected static ?string $navigationIcon = 'heroicon-o-photo';
2724

25+
protected static ?string $recordTitleAttribute = 'name';
26+
2827
public static function getNavigationLabel(): string
2928
{
3029
return trans('filament-flexible-blocks-asset-manager::filament-flexible-blocks-asset-manager.asset_nav_lbl');
@@ -40,20 +39,33 @@ public static function getPluralLabel(): string
4039
return trans('filament-flexible-blocks-asset-manager::filament-flexible-blocks-asset-manager.asset_plural_lbl');
4140
}
4241

42+
public static function getModel(): string
43+
{
44+
return FilamentFlexibleBlocksAssetManagerConfig::getModel();
45+
}
46+
4347
public static function getNavigationGroup(): ?string
4448
{
4549
return FilamentFlexibleBlocksAssetManagerConfig::getNavigationGroup();
4650
}
4751

52+
public static function getDefaultComponents(): array
53+
{
54+
return [
55+
AssetNameField::create(true),
56+
AssetMediaField::create(FilamentFlexibleBlocksAssetManagerConfig::hasTranslatableAssets())
57+
->required(),
58+
];
59+
}
60+
4861
public static function form(Form $form): Form
4962
{
5063
return $form
5164
->schema([
5265
Section::make()
5366
->columns(2)
5467
->schema([
55-
AssetNameField::create(true),
56-
AssetMediaField::create(FilamentFlexibleBlocksAssetManagerConfig::hasTranslatableAssets()),
68+
...static::getDefaultComponents(),
5769
]),
5870
]);
5971
}
@@ -75,6 +87,7 @@ public static function table(Table $table): Table
7587
// Only render the tooltip if the column contents exceeds the length limit.
7688
return $state;
7789
})
90+
->searchable()
7891
->sortable(),
7992
])
8093
->actions([

src/Filament/Resources/AssetResource/Pages/CreateAsset.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Filament\Actions;
66
use Filament\Resources\Pages\CreateRecord;
77
use Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource;
8+
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
89
use Statikbe\FilamentFlexibleContentBlocks\Filament\Pages\CreateRecord\Concerns\TranslatableWithMedia;
910

1011
class CreateAsset extends CreateRecord
@@ -13,6 +14,11 @@ class CreateAsset extends CreateRecord
1314

1415
protected static string $resource = AssetResource::class;
1516

17+
public static function getResource(): string
18+
{
19+
return FilamentFlexibleBlocksAssetManagerConfig::getResource();
20+
}
21+
1622
protected function getHeaderActions(): array
1723
{
1824
return [

src/Filament/Resources/AssetResource/Pages/EditAsset.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Filament\Actions;
66
use Filament\Resources\Pages\EditRecord;
77
use Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource;
8+
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
89
use Statikbe\FilamentFlexibleContentBlocks\Filament\Pages\EditRecord\Concerns\TranslatableWithMedia;
910

1011
class EditAsset extends EditRecord
@@ -13,6 +14,11 @@ class EditAsset extends EditRecord
1314

1415
protected static string $resource = AssetResource::class;
1516

17+
public static function getResource(): string
18+
{
19+
return FilamentFlexibleBlocksAssetManagerConfig::getResource();
20+
}
21+
1622
protected function getHeaderActions(): array
1723
{
1824
return [

src/Filament/Resources/AssetResource/Pages/ListAssets.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
use Filament\Resources\Pages\ListRecords;
77
use Filament\Resources\Pages\ListRecords\Concerns\Translatable;
88
use Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource;
9+
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
910

1011
class ListAssets extends ListRecords
1112
{
1213
use Translatable;
1314

1415
protected static string $resource = AssetResource::class;
1516

17+
public static function getResource(): string
18+
{
19+
return FilamentFlexibleBlocksAssetManagerConfig::getResource();
20+
}
21+
1622
protected function getHeaderActions(): array
1723
{
1824
return [

src/FilamentFlexibleBlocksAssetManagerConfig.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public static function getAssetAuthorisationPolicy(): ?string
1919
return self::getConfig('asset_authorisation.policy');
2020
}
2121

22+
public static function getAssetMiddleware(): ?string
23+
{
24+
return self::getConfig('asset_authorisation.middleware');
25+
}
26+
2227
public static function getStorageDisk(): ?string
2328
{
2429
return self::getConfig('storage_disk');
@@ -49,6 +54,16 @@ public static function getNavigationGroup(): ?string
4954
return self::getConfig('navigation_group') ?? trans('filament-flexible-blocks-asset-manager::filament-flexible-blocks-asset-manager.navigation_group');
5055
}
5156

57+
public static function getModel(): ?string
58+
{
59+
return self::getConfig('model');
60+
}
61+
62+
public static function getResource(): ?string
63+
{
64+
return self::getConfig('resource');
65+
}
66+
5267
public static function getAssetRoutePrefix(): ?string
5368
{
5469
return self::getConfig('asset_route_prefix', '/asset');

src/FilamentFlexibleBlocksAssetManagerPlugin.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Filament\Contracts\Plugin;
66
use Filament\Panel;
7-
use Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Resources\AssetResource;
87

98
class FilamentFlexibleBlocksAssetManagerPlugin implements Plugin
109
{
@@ -16,7 +15,7 @@ public function getId(): string
1615
public function register(Panel $panel): void
1716
{
1817
$panel->resources([
19-
AssetResource::class,
18+
FilamentFlexibleBlocksAssetManagerConfig::getResource(),
2019
]);
2120
}
2221

0 commit comments

Comments
 (0)