generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Feature: Generate a Filament Plugin for a specified Module
- Loading branch information
1 parent
128fad9
commit 2561e68
Showing
7 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Coolsam\Modules\Commands; | ||
|
||
use Coolsam\Modules\Concerns\GeneratesModularFiles; | ||
use Illuminate\Console\GeneratorCommand; | ||
|
||
class ModuleMakeFilamentPluginCommand extends GeneratorCommand | ||
{ | ||
use GeneratesModularFiles; | ||
|
||
protected $name = 'module:make:filament-plugin'; | ||
|
||
protected $description = 'Create a new Filament Plugin class in the module'; | ||
|
||
protected $type = 'Filament Plugin'; | ||
|
||
protected function getRelativeNamespace(): string | ||
{ | ||
return 'App\\Filament'; | ||
} | ||
|
||
protected function getStub(): string | ||
{ | ||
return $this->resolveStubPath('/stubs/filament-plugin.stub'); | ||
} | ||
|
||
protected function stubReplacements(): array | ||
{ | ||
return [ | ||
'moduleStudlyName' => $this->getModule()->getStudlyName(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use Filament\Contracts\Plugin; | ||
use Filament\Panel; | ||
use Illuminate\Support\Str; | ||
use Nwidart\Modules\Facades\Module; | ||
|
||
class {{ class }} implements Plugin | ||
{ | ||
public function getModuleName(): string | ||
{ | ||
return '{{ moduleStudlyName }}'; | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return Str::of($this->getModuleName())->lower()->append('-module')->toString(); | ||
} | ||
|
||
public function getModule(): \Nwidart\Modules\Module | ||
{ | ||
return Module::findOrFail($this->getModuleName()); | ||
} | ||
|
||
public function register(Panel $panel): void | ||
{ | ||
$module = $this->getModule(); | ||
$useClusters = config('filament-modules.clusters.enabled', false); | ||
$panel->discoverPages( | ||
in: $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Pages'), | ||
for: $module->appNamespace('\\Filament\\Pages') | ||
); | ||
$panel->discoverResources( | ||
in: $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Resources'), | ||
for: $module->appNamespace('\\Filament\\Resources') | ||
); | ||
$panel->discoverWidgets( | ||
in: $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Widgets'), | ||
for: $module->appNamespace('\\Filament\\Widgets') | ||
); | ||
|
||
$panel->discoverLivewireComponents( | ||
in: $module->appPath('Livewire'), | ||
for: $module->appNamespace('\\Livewire') | ||
); | ||
|
||
if ($useClusters) { | ||
$path = $module->appPath('Filament'.DIRECTORY_SEPARATOR.'Clusters'); | ||
$namespace = $module->appNamespace('\\Filament\\Clusters'); | ||
$panel->discoverClusters( | ||
in: $path, | ||
for: $namespace, | ||
); | ||
} | ||
} | ||
|
||
public function boot(Panel $panel): void | ||
{ | ||
// TODO: Implement boot() method. | ||
} | ||
|
||
public static function make(): static | ||
{ | ||
return app(static::class); | ||
} | ||
|
||
public static function get(): static | ||
{ | ||
/** @var static $plugin */ | ||
$plugin = filament(app(static::class)->getId()); | ||
|
||
return $plugin; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters