Skip to content

Commit 43bae3e

Browse files
committed
configurable routing + documentation
1 parent 05c5905 commit 43bae3e

File tree

5 files changed

+92
-29
lines changed

5 files changed

+92
-29
lines changed

README.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# A simple document and image manager for the Filament Flexible Blocks package.
1+
# Laravel Filament Flexible Blocks Asset Manager
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/statik-be/laravel-filament-flexible-blocks-asset-manager.svg?style=flat-square)](https://packagist.org/packages/statik-be/laravel-filament-flexible-blocks-asset-manager)
44
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/statik-be/laravel-filament-flexible-blocks-asset-manager/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/statik-be/laravel-filament-flexible-blocks-asset-manager/actions?query=workflow%3Arun-tests+branch%3Amain)
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/statik-be/laravel-filament-flexible-blocks-asset-manager/fix-php-code-styling.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/statik-be/laravel-filament-flexible-blocks-asset-manager/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/statik-be/laravel-filament-flexible-blocks-asset-manager.svg?style=flat-square)](https://packagist.org/packages/statik-be/laravel-filament-flexible-blocks-asset-manager)
77

8+
This package provides a simple document and image manager for the [Laravel Filament Flexible Content Blocks](https://github.com/statikbe/laravel-filament-flexible-content-blocks) package.
89

10+
The key features are:
911

10-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
12+
- a simple asset model
13+
- integration with the call-to-action features of the [Laravel Filament Flexible Content Blocks](https://github.com/statikbe/laravel-filament-flexible-content-blocks) package.
14+
- basic filament CRUD UI
15+
- routing to retrieve the assets
1116

1217
## Installation
1318

@@ -30,31 +35,55 @@ You can publish the config file with:
3035
php artisan vendor:publish --tag="laravel-filament-flexible-blocks-asset-manager-config"
3136
```
3237

33-
Optionally, you can publish the views using
38+
Optionally, you can publish the translations using
3439

3540
```bash
36-
php artisan vendor:publish --tag="laravel-filament-flexible-blocks-asset-manager-views"
41+
php artisan vendor:publish --tag="laravel-filament-flexible-blocks-asset-manager-translations"
3742
```
3843

39-
This is the contents of the published config file:
44+
### Setup with the Filament Flexible Content Blocks package
45+
46+
To integrate the plugin with Filament, you need to add it a panel in the filament service provider. See the code sample below:
4047

4148
```php
42-
return [
43-
];
49+
public function panel(Panel $panel): Panel
50+
{
51+
return $panel
52+
->default()
53+
//...
54+
->plugins([
55+
SpatieLaravelTranslatablePlugin::make()
56+
->defaultLocales(['nl']),
57+
//...
58+
FilamentFlexibleBlocksAssetManagerPlugin::make()
59+
]);
60+
}
4461
```
4562

46-
## Usage
63+
Then to use the asset manager in the call-to-actions you have to add them to the configuration of the Filament Flexible
64+
Content Blocks package:
4765

4866
```php
49-
$laravelFilamentFlexibleBlocksAssetManager = new Statikbe\LaravelFilamentFlexibleBlocksAssetManager();
50-
echo $laravelFilamentFlexibleBlocksAssetManager->echoPhrase('Hello, Statikbe!');
67+
return [
68+
//...
69+
70+
'call_to_action_models' => [
71+
[
72+
'model' => \Statikbe\FilamentFlexibleBlocksAssetManager\Models\Asset::class,
73+
'call_to_action_type' => \Statikbe\FilamentFlexibleBlocksAssetManager\Filament\Form\Fields\Blocks\Type\AssetCallToActionType::class,
74+
],
75+
//...
76+
//\App\Models\TranslatablePage::class,
77+
],
78+
79+
//...
80+
]
5181
```
5282

53-
## Testing
83+
## Configuration
5484

55-
```bash
56-
composer test
57-
```
85+
The configuration file is [filament-flexible-blocks-asset-manager.php](config%2Ffilament-flexible-blocks-asset-manager.php)
86+
fully commented, to explain each configuration option.
5887

5988
## Changelog
6089

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,15 @@
9898
'asset_authorisation' => [
9999
//'gate' => 'asset-access',
100100
//'policy' => AssetPolicy::class,
101-
]
101+
],
102+
103+
/*
104+
|--------------------------------------------------------------------------
105+
| Asset route prefix
106+
|--------------------------------------------------------------------------
107+
|
108+
| You can change the start of the route path by setting this config.
109+
| Do not add a slash as the last character this will be added automatically.
110+
*/
111+
'asset_route_prefix' => '/asset'
102112
];
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4+
use Illuminate\Support\Str;
5+
use Statikbe\FilamentFlexibleBlocksAssetManager\FilamentFlexibleBlocksAssetManagerConfig;
46
use Statikbe\FilamentFlexibleBlocksAssetManager\Http\Controllers\AssetController;
57

68

7-
Route::get('/asset/{asset}/{locale?}', [AssetController::class, 'index'])
9+
$assetRoutePrefix = FilamentFlexibleBlocksAssetManagerConfig::getAssetRoutePrefix();
10+
$assetRoutePrefix = Str::replaceEnd('/', '', $assetRoutePrefix);
11+
12+
Route::get("$assetRoutePrefix/{asset}/{locale?}", [AssetController::class, 'index'])
813
->middleware(['web'])
914
->name('filament-flexible-blocks-asset-manager.asset_index');

src/FilamentFlexibleBlocksAssetManagerConfig.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,56 @@ class FilamentFlexibleBlocksAssetManagerConfig
66
{
77
public static function hasTranslatableAssets(): bool
88
{
9-
return config('filament-flexible-blocks-asset-manager.translatable_assets', false);
9+
return self::getConfig('translatable_assets', false);
1010
}
1111

1212
public static function getAssetAuthorisationGate(): ?string
1313
{
14-
return config('filament-flexible-blocks-asset-manager.asset_authorisation.gate');
14+
return self::getConfig('asset_authorisation.gate');
1515
}
1616

1717
public static function getAssetAuthorisationPolicy(): ?string
1818
{
19-
return config('filament-flexible-blocks-asset-manager.asset_authorisation.policy');
19+
return self::getConfig('asset_authorisation.policy');
2020
}
2121

2222
public static function getStorageDisk(): ?string
2323
{
24-
return config('filament-flexible-blocks-asset-manager.storage_disk');
24+
return self::getConfig('storage_disk');
2525
}
2626

2727
public static function getStorageDirectory(): ?string
2828
{
29-
return config('filament-flexible-blocks-asset-manager.storage_directory');
29+
return self::getConfig('storage_directory');
3030
}
3131

3232
public static function getStorageVisibility(): ?string
3333
{
34-
return config('filament-flexible-blocks-asset-manager.storage_visibility') ?? 'public';
34+
return self::getConfig('storage_visibility') ?? 'public';
3535
}
3636

3737
public static function getAcceptedFileTypes(): array
3838
{
39-
return config('filament-flexible-blocks-asset-manager.accepted_file_types') ?? [];
39+
return self::getConfig('accepted_file_types') ?? [];
4040
}
4141

4242
public static function getImageEditor(): array|null
4343
{
44-
return config('filament-flexible-blocks-asset-manager.image_editor', null);
44+
return self::getConfig('image_editor', null);
4545
}
4646

4747
public static function getNavigationGroup(): ?string
4848
{
49-
return config('filament-flexible-blocks-asset-manager.navigation_group');
49+
return self::getConfig('navigation_group');
50+
}
51+
52+
public static function getAssetRoutePrefix(): ?string
53+
{
54+
return self::getConfig('asset_route_prefix', '/asset');
55+
}
56+
57+
public static function getConfig($key = null, $default = null)
58+
{
59+
return config('filament-flexible-blocks-asset-manager.' . $key, $default);
5060
}
5161
}

src/Models/Asset.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
use Spatie\Translatable\HasTranslations;
1111
use Statikbe\FilamentFlexibleContentBlocks\Models\Concerns\HasTranslatedMediaTrait;
1212
use Statikbe\FilamentFlexibleContentBlocks\Models\Contracts\HasTranslatableMedia;
13+
use Statikbe\FilamentFlexibleContentBlocks\Models\Contracts\Linkable;
1314

1415
/**
1516
* @property string $name
1617
*/
17-
class Asset extends Model implements HasMedia, HasTranslatableMedia
18+
class Asset extends Model implements HasMedia, HasTranslatableMedia, Linkable
1819
{
1920
use HasTranslations;
2021
use InteractsWithMedia;
@@ -44,8 +45,16 @@ public function getAssetCollection(): string
4445
return self::MEDIA_COLLECTION_ASSETS;
4546
}
4647

47-
/*public function getMorphClass(): string
48+
public function getViewUrl(?string $locale = null): string
4849
{
49-
return 'filament-flexible-blocks-asset-manager::asset';
50-
}*/
50+
return route('filament-flexible-blocks-asset-manager.asset_index', [
51+
'asset' => $this,
52+
'locale' => $locale,
53+
]);
54+
}
55+
56+
public function getPreviewUrl(?string $locale = null): string
57+
{
58+
$this->getViewUrl($locale);
59+
}
5160
}

0 commit comments

Comments
 (0)