Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,15 @@ protected function bootFormConfigFields(): self
'type' => 'select',
'display' => __('View'),
'instructions' => __('Choose the view for this form.'),
'options' => collect(File::files(resource_path('views/'.config('livewire-forms.view_path'))))
->map(fn ($file) => Str::before($file->getBasename(), '.'))
->mapWithKeys(fn ($view) => [$view => str($view)->replace(['_', '-'], ' ')->title()->toString()]),
'options' => $this->viewOptions(),
'clearable' => true,
'width' => 50,
],
'theme' => [
'type' => 'select',
'display' => __('Theme'),
'instructions' => __('Choose the theme for this form.'),
'options' => collect(File::directories(resource_path('views/'.config('livewire-forms.view_path'))))
->map(fn ($directory) => basename($directory))
->mapWithKeys(fn ($theme) => [$theme => str($theme)->replace(['_', '-'], ' ')->title()->toString()]),
'options' => $this->themeOptions(),
'clearable' => true,
'width' => 50,
],
Expand All @@ -120,4 +116,32 @@ protected function bootFormConfigFields(): self

return $this;
}

protected function viewOptions(): ?array
{
$path = resource_path('views/'.config('livewire-forms.view_path'));

if (! File::isDirectory($path)) {
return null;
}

return collect(File::files($path))
->map(fn ($file) => Str::before($file->getBasename(), '.'))
->mapWithKeys(fn ($view) => [$view => str($view)->replace(['_', '-'], ' ')->title()->toString()])
->all();
}

protected function themeOptions(): ?array
{
$path = resource_path('views/'.config('livewire-forms.view_path'));

if (! File::isDirectory($path)) {
return null;
}

return collect(File::directories($path))
->map(fn ($directory) => basename($directory))
->mapWithKeys(fn ($theme) => [$theme => str($theme)->replace(['_', '-'], ' ')->title()->toString()])
->all();
}
}
Loading