Skip to content

Commit

Permalink
fix: support filament v3
Browse files Browse the repository at this point in the history
  • Loading branch information
daurensky committed Feb 12, 2024
1 parent 2912619 commit f60b8fa
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 44 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,21 @@ php artisan vendor:publish --tag="admin-kit-articles-views"
## Usage

```php
$articles = new AdminKit\Articles();
echo $articles->echoPhrase('Hello, AdminKit!');
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
...
->plugins([
...
\AdminKit\Articles\FilamentPlugin::make(),
]);
}
}
```

## Testing
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"php": "^8.1",
"cviebrock/eloquent-sluggable": "^10.0",
"illuminate/contracts": "^10.0",
"ibecsystems/admin-kit-core": "^2.2",
"ibecsystems/admin-kit-seo": "^2.2",
"ibecsystems/admin-kit-core": "^3.1",
"ibecsystems/admin-kit-seo": "^3.0",
"spatie/laravel-package-tools": "^1.14.0",
"spatie/laravel-data": "^3.2",
"spatie/laravel-json-api-paginate": "^1.13",
"spatie/laravel-query-builder": "^5.2"
"spatie/laravel-query-builder": "^5.7"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
1 change: 0 additions & 1 deletion resources/lang/en/articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'resource' => [
'label' => 'News',
'plural_label' => 'News',
'cropper_title' => 'Crop image',

'id' => 'ID',
'image' => 'Image',
Expand Down
1 change: 0 additions & 1 deletion resources/lang/ru/articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'resource' => [
'label' => 'Новость',
'plural_label' => 'Новости',
'cropper_title' => 'Обрезать изображение',

'id' => 'ID',
'image' => 'Изображение',
Expand Down
4 changes: 1 addition & 3 deletions src/ArticlesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace AdminKit\Articles;

use Spatie\LaravelPackageTools\Package;
use AdminKit\Articles\Commands\ArticlesCommand;
use AdminKit\Articles\Providers\FilamentServiceProvider;
use AdminKit\Articles\Providers\RouteServiceProvider;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class ArticlesServiceProvider extends PackageServiceProvider
Expand All @@ -29,6 +28,5 @@ public function configurePackage(Package $package): void
public function registeringPackage()
{
$this->app->register(RouteServiceProvider::class);
$this->app->register(FilamentServiceProvider::class);
}
}
31 changes: 31 additions & 0 deletions src/FilamentPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace AdminKit\Articles;

use Filament\Panel;
use Filament\Contracts\Plugin;
use AdminKit\Articles\UI\Filament\Resources\ArticleResource;

class FilamentPlugin implements Plugin
{
public function getId(): string
{
return 'filament-plugin-admin-kit-articles';
}

public function register(Panel $panel): void
{
$panel->resources([
ArticleResource::class,
]);
}

public function boot(Panel $panel): void
{
}

public static function make(): static
{
return app(static::class);
}
}
17 changes: 0 additions & 17 deletions src/Providers/FilamentServiceProvider.php

This file was deleted.

19 changes: 6 additions & 13 deletions src/UI/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

use AdminKit\Articles\Models\Article;
use AdminKit\Articles\UI\Filament\Resources\ArticleResource\Pages;
use AdminKit\Core\Forms\Components\AdminKitCropper;
use AdminKit\Core\Forms\Components\TranslatableTabs;
use AdminKit\SEO\Forms\Components\SEOComponent;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Support\Str;

Expand All @@ -20,28 +17,24 @@ class ArticleResource extends Resource

protected static ?string $recordTitleAttribute = 'title';

protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
public static function form(Forms\Form $form): Forms\Form
{
$rows = [];
if (config('admin-kit-articles.image.enabled')) {
$rows[] = AdminKitCropper::make('image')
$rows[] = Forms\Components\SpatieMediaLibraryFileUpload::make('image')
->label(__('admin-kit-articles::articles.resource.image'))
->image()
->required()
->columnSpan(2)
->imageEditor()

// image properties
->imageCropAspectRatio(config('admin-kit-articles.image.crop_aspect_ratio'))
->imageResizeTargetWidth(config('admin-kit-articles.image.resize_target_width'))
->imageResizeTargetHeight(config('admin-kit-articles.image.resize_target_height'))
->imagePreviewHeight(config('admin-kit-articles.image.preview_height'))

// cropper properties
->modalHeading(__('admin-kit-articles::articles.resource.cropper_header'))
->modalSize('2xl')
->zoomable(false);
->imagePreviewHeight(config('admin-kit-articles.image.preview_height'));
}

$rows[] = TranslatableTabs::make(fn ($locale) => Forms\Components\Tabs\Tab::make($locale)
Expand Down Expand Up @@ -90,7 +83,7 @@ function (string $context, $state, callable $set) {
return $form->schema($rows);
}

public static function table(Table $table): Table
public static function table(Tables\Table $table): Tables\Table
{
return $table
->columns([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace AdminKit\Articles\UI\Filament\Resources\ArticleResource\Pages;

use AdminKit\Articles\UI\Filament\Resources\ArticleResource;
use Filament\Pages\Actions;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditArticle extends EditRecord
{
protected static string $resource = ArticleResource::class;

protected function getActions(): array
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace AdminKit\Articles\UI\Filament\Resources\ArticleResource\Pages;

use AdminKit\Articles\UI\Filament\Resources\ArticleResource;
use Filament\Pages\Actions;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListArticles extends ListRecords
{
protected static string $resource = ArticleResource::class;

protected function getActions(): array
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
Expand Down

0 comments on commit f60b8fa

Please sign in to comment.