From be7947051502da077aefd038c33e12ec65828c91 Mon Sep 17 00:00:00 2001 From: Fady Mondy Date: Mon, 16 Sep 2024 17:01:52 +0300 Subject: [PATCH] add filament-plugins integration --- module.json | 29 ++++++++++++++++++++++ src/FilamentLocationsPlugin.php | 44 ++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 module.json diff --git a/module.json b/module.json new file mode 100644 index 0000000..e38c18e --- /dev/null +++ b/module.json @@ -0,0 +1,29 @@ +{ + "name": "FilamentLocations", + "alias": "filament-locations", + "description": { + "ar": "بيانات الدول والمناطق مخزنة في قاعدة البيانات", + "en": "Database Seeds for Locations for FilamentPHP", + "gr": "Database Seeds for Locations for FilamentPHP", + "sp": "Database Seeds for Locations for FilamentPHP" + }, + "keywords": [], + "priority": 0, + "providers": [ + "TomatoPHP\\FilamentLocations\\FilamentLocationsServiceProvider" + ], + "files": [], + "title": { + "ar": "المناطق", + "en": "Locations Seeder", + "gr": "Locations Seeder", + "sp": "Locations Seeder" + }, + "color": "#cc1448", + "icon": "heroicon-c-globe-asia-australia", + "placeholder": "https://raw.githubusercontent.com/tomatophp/filament-locations/master/arts/3x1io-tomato-locations.jpg", + "type": "plugin", + "version": "v1.0.4", + "github" : "https://github.com/tomatophp/filament-locations", + "docs" : "https://github.com/tomatophp/filament-locations" +} diff --git a/src/FilamentLocationsPlugin.php b/src/FilamentLocationsPlugin.php index 31a38aa..7b91d09 100644 --- a/src/FilamentLocationsPlugin.php +++ b/src/FilamentLocationsPlugin.php @@ -5,6 +5,7 @@ use Filament\Contracts\Plugin; use Filament\Panel; use Illuminate\View\View; +use Nwidart\Modules\Module; use TomatoPHP\FilamentLocations\Resources\AreaResource; use TomatoPHP\FilamentLocations\Resources\CityResource; use TomatoPHP\FilamentLocations\Resources\CountryResource; @@ -14,6 +15,8 @@ class FilamentLocationsPlugin implements Plugin { + private bool $isActive = false; + public function getId(): string { return 'filament-locations'; @@ -21,24 +24,35 @@ public function getId(): string public function register(Panel $panel): void { - $resources = []; - if(config('filament-locations.resources.city')){ - $resources[] = CityResource::class; - } - if(config('filament-locations.resources.country')){ - $resources[] = CountryResource::class; - } - if(config('filament-locations.resources.languages')){ - $resources[] = LanguageResource::class; + if(class_exists(Module::class)){ + if(\Nwidart\Modules\Facades\Module::find('FilamentLocations')->isEnabled()){ + $this->isActive = true; + } } - if(config('filament-locations.resources.currency')){ - $resources[] = CurrencyResource::class; - } - if(config('filament-locations.resources.locations')){ - $resources[] = LocationResource::class; + else { + $this->isActive = true; } - $panel->resources($resources); + if($this->isActive) { + $resources = []; + if (config('filament-locations.resources.city')) { + $resources[] = CityResource::class; + } + if (config('filament-locations.resources.country')) { + $resources[] = CountryResource::class; + } + if (config('filament-locations.resources.languages')) { + $resources[] = LanguageResource::class; + } + if (config('filament-locations.resources.currency')) { + $resources[] = CurrencyResource::class; + } + if (config('filament-locations.resources.locations')) { + $resources[] = LocationResource::class; + } + + $panel->resources($resources); + } } public function boot(Panel $panel): void