mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-29 18:19:53 +08:00
clean up and support view namespacing for page generation
This commit is contained in:
@@ -26,6 +26,7 @@ use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Exceptions\InvalidCommandOutput;
|
||||
use Filament\Support\Commands\FileGenerators\Concerns\CanCheckFileGenerationFlags;
|
||||
use Filament\Support\Commands\FileGenerators\FileGenerationFlag;
|
||||
use Filament\Support\Facades\FilamentCli;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@@ -354,11 +355,17 @@ class MakePageCommand extends Command
|
||||
$this->fqn = $this->pagesNamespace . '\\' . $this->fqnEnd;
|
||||
|
||||
if ((! $this->hasResource) || ($this->resourcePageType === ResourcePage::class)) {
|
||||
$componentLocations = FilamentCli::getComponentLocations();
|
||||
|
||||
$matchingComponentLocationNamespaces = collect($componentLocations)
|
||||
->keys()
|
||||
->filter(fn (string $namespace): bool => str($this->fqn)->startsWith($namespace));
|
||||
|
||||
[
|
||||
$this->view,
|
||||
$this->viewPath,
|
||||
] = $this->askForViewLocation(
|
||||
str($this->fqn)
|
||||
view: str($this->fqn)
|
||||
->whenContains(
|
||||
'Filament\\',
|
||||
fn (Stringable $fqn) => $fqn->after('Filament\\')->prepend('Filament\\'),
|
||||
@@ -368,6 +375,10 @@ class MakePageCommand extends Command
|
||||
->explode('/')
|
||||
->map(Str::kebab(...))
|
||||
->implode('.'),
|
||||
question: 'Where would you like to create the Blade view for the page?',
|
||||
defaultNamespace: (count($matchingComponentLocationNamespaces) === 1)
|
||||
? $componentLocations[Arr::first($matchingComponentLocationNamespaces)]['viewNamespace'] ?? null
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ trait CanAskForComponentLocation
|
||||
* @return array{
|
||||
* 0: string,
|
||||
* 1: string,
|
||||
* 3: ?string,
|
||||
* 2: ?string,
|
||||
* }
|
||||
*/
|
||||
protected function askForComponentLocation(string $path, string $question = 'Where would you like to create the component?'): array
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\FileViewFinder;
|
||||
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
@@ -21,11 +22,17 @@ trait CanAskForViewLocation
|
||||
|
||||
$paths = [];
|
||||
|
||||
if (str(Arr::first(config('view.paths')))->startsWith(base_path())) {
|
||||
$paths[''] = Arr::first(config('view.paths'));
|
||||
/** @var array<string> $viewPaths */
|
||||
$viewPaths = config('view.paths') ?? [];
|
||||
|
||||
if (str(Arr::first($viewPaths))->startsWith(base_path())) {
|
||||
$paths[''] = Arr::first($viewPaths);
|
||||
}
|
||||
|
||||
foreach ($viewFactory->getFinder()->getHints() as $namespace => $hintPaths) {
|
||||
/** @var FileViewFinder $viewFinder */
|
||||
$viewFinder = $viewFactory->getFinder();
|
||||
|
||||
foreach ($viewFinder->getHints() as $namespace => $hintPaths) {
|
||||
foreach ($hintPaths as $path) {
|
||||
if (! str($path)->startsWith(base_path())) {
|
||||
continue;
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static void registerComponentLocation(string $directory, string $namespace, ?string $viewNamespace = null)
|
||||
* @method static array<string, string> getComponentLocations()
|
||||
* @method static array<string, array{path: string, viewNamespace: ?string}> getComponentLocations()
|
||||
*
|
||||
* @see CliManager
|
||||
*/
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace {{ namespace }};
|
||||
|
||||
use Filament\Tables\Columns\Column;
|
||||
|
||||
class {{ class }} extends Column
|
||||
{
|
||||
protected string $view = '{{ view }}';
|
||||
}
|
||||
Reference in New Issue
Block a user