diff --git a/resources/js/bootstrap/cp.ts b/resources/js/bootstrap/cp.ts index cd2808a7db9..3d8105c7409 100644 --- a/resources/js/bootstrap/cp.ts +++ b/resources/js/bootstrap/cp.ts @@ -15,6 +15,7 @@ import AssetIndexes from '@/components/utilities/AssetIndexes/AssetIndexes.vue'; import SystemMessages from '@/components/utilities/SystemMessages/SystemMessages.vue'; import DeprecationErrorsToolbar from '@/components/utilities/DeprecationErrors/DeprecationErrorsToolbar.vue'; import {setTranslations} from '@craftcms/cp/utilities/translate.ts.mjs'; +import LocalFsSettings from '@/components/Filesystems/LocalFsSettings.vue'; let bootedCallbacks: Array<(instance: any) => void> = []; let bootingCallbacks: Array<(instance: any) => void> = []; @@ -98,6 +99,9 @@ const Cp = { app.component('ProjectConfig', ProjectConfig); app.component('AssetIndexes', AssetIndexes); app.component('SystemMessages', SystemMessages); + app.component('LocalFsSettings', LocalFsSettings); + + // @TODO Register plugin components }, }); diff --git a/resources/js/components/Filesystems/FilesystemSettings.vue b/resources/js/components/Filesystems/FilesystemSettings.vue new file mode 100644 index 00000000000..86349c08cf2 --- /dev/null +++ b/resources/js/components/Filesystems/FilesystemSettings.vue @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + diff --git a/resources/js/components/Filesystems/LocalFsSettings.vue b/resources/js/components/Filesystems/LocalFsSettings.vue new file mode 100644 index 00000000000..c30f94d82f9 --- /dev/null +++ b/resources/js/components/Filesystems/LocalFsSettings.vue @@ -0,0 +1,18 @@ + + + + Roundabout LocalFsSettings + + + + + diff --git a/resources/js/pages/SettingsFilesystemsEditPage.vue b/resources/js/pages/SettingsFilesystemsEditPage.vue new file mode 100644 index 00000000000..f0fca56f7fd --- /dev/null +++ b/resources/js/pages/SettingsFilesystemsEditPage.vue @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/templates/_components/fs/Local/settings.twig b/resources/templates/_components/fs/Local/settings.twig index e790bc638ee..587bce0cfbd 100644 --- a/resources/templates/_components/fs/Local/settings.twig +++ b/resources/templates/_components/fs/Local/settings.twig @@ -1,17 +1,23 @@ {% from "_includes/forms" import autosuggestField %} + + {{ autosuggestField({ - label: "Base Path"|t('app'), - instructions: "The base folder path that should be used as the root of the filesystem."|t('app'), - id: 'path', - class: 'ltr', - name: 'path', - suggestEnvVars: true, - suggestAliases: true, - value: filesystem.path, - required: true, - placeholder: "/path/to/folder"|t('app'), - errors: filesystem.errors.get('path'), - data: {'error-key': 'path'}, - disabled: readOnly, + label: "Base Path"|t('app'), + instructions: "The base folder path that should be used as the root of the filesystem."|t('app'), + id: 'path', + class: 'ltr', + name: 'path', + suggestEnvVars: true, + suggestAliases: true, + value: filesystem.path, + required: true, + placeholder: "/path/to/folder"|t('app'), + errors: filesystem.errors.get('path'), + data: {'error-key': 'path'}, + disabled: readOnly, }) }} diff --git a/src/Cp/JsonResource.php b/src/Cp/JsonResource.php new file mode 100644 index 00000000000..40483a9d3e1 --- /dev/null +++ b/src/Cp/JsonResource.php @@ -0,0 +1,11 @@ + $this, + return Html::tag('LocalFsSettings', attributes: [ + // ':filesystem' => json_encode([ + // 'name' => $this->name, + // 'handle' => $this->handle, + // ]), 'readOnly' => $readOnly, - ], TemplateMode::Cp); + ]); + // return template('_components/fs/Local/settings', [ + // 'filesystem' => $this, + // 'readOnly' => $readOnly, + // ], TemplateMode::Cp); } #[Override] diff --git a/src/Filesystem/Resources/FsResource.php b/src/Filesystem/Resources/FsResource.php index 5fe080dae83..c0fda97c253 100644 --- a/src/Filesystem/Resources/FsResource.php +++ b/src/Filesystem/Resources/FsResource.php @@ -4,11 +4,11 @@ namespace CraftCms\Cms\Filesystem\Resources; +use CraftCms\Cms\Cp\JsonResource; use CraftCms\Cms\Filesystem\Filesystems\Filesystem; use CraftCms\Cms\Filesystem\Filesystems\MissingFs; use CraftCms\Cms\Support\Arr; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\JsonResource; /** * @mixin Filesystem diff --git a/src/Gql/Resources/GqlTokenResource.php b/src/Gql/Resources/GqlTokenResource.php index 192c1992c0b..86a6688ba65 100644 --- a/src/Gql/Resources/GqlTokenResource.php +++ b/src/Gql/Resources/GqlTokenResource.php @@ -4,10 +4,10 @@ namespace CraftCms\Cms\Gql\Resources; +use CraftCms\Cms\Cp\JsonResource; use CraftCms\Cms\Gql\Data\GqlToken; use DateTime; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\JsonResource; /** * @mixin GqlToken diff --git a/src/Http/Controllers/Settings/FilesystemsController.php b/src/Http/Controllers/Settings/FilesystemsController.php index 5b9b65bf611..290d48403fc 100644 --- a/src/Http/Controllers/Settings/FilesystemsController.php +++ b/src/Http/Controllers/Settings/FilesystemsController.php @@ -6,6 +6,7 @@ use CraftCms\Cms\Config\GeneralConfig; use CraftCms\Cms\Cp\Html\ContentHtml; +use CraftCms\Cms\Cp\SelectOptions; use CraftCms\Cms\Filesystem\Contracts\FsInterface; use CraftCms\Cms\Filesystem\Filesystems; use CraftCms\Cms\Filesystem\Resources\FsResource; @@ -13,6 +14,7 @@ use CraftCms\Cms\Http\Responses\CpScreenResponse; use CraftCms\Cms\Support\Arr; use CraftCms\Cms\Support\Html; +use CraftCms\Cms\Support\Str; use CraftCms\Cms\Support\Url; use Illuminate\Http\Request; use Inertia\Inertia; @@ -93,18 +95,36 @@ public function edit(?string $handle = null): CpScreenResponse $title = t('Create a new filesystem'); } + $isValidUrl = fn ($value) => Str::isUrl($value); + return new CpScreenResponse() ->title($title) ->addCrumb(t('Settings'), 'settings') ->addCrumb(t('Filesystems'), 'settings/filesystems') - ->contentTemplate('settings/filesystems/_edit.twig', [ + ->inertiaPage('SettingsFilesystemsEditPage', [ 'oldHandle' => $handle, - 'filesystem' => $filesystem, + 'filesystem' => [ + ...$filesystem, + 'type' => $filesystem::class, + 'settingsHtml' => $this->readOnly ? $filesystem->getReadOnlySettingsHtml() : $filesystem->getSettingsHtml(), + 'showHasUrlSetting' => $filesystem->getShowHasUrlSetting(), + 'showUrlSetting' => $filesystem->getShowUrlSetting(), + ], 'fsOptions' => $fsOptions, 'fsInstances' => $fsInstances, 'fsTypes' => $allFsTypes, - 'readOnly' => $this->readOnly, + + // @TODO this should probably be its own item on SelectOptions + 'baseUrlSuggestions' => SelectOptions::getEnvSuggestions(true, $isValidUrl), ]) + // ->contentTemplate('settings/filesystems/_edit.twig', [ + // 'oldHandle' => $handle, + // 'filesystem' => $filesystem, + // 'fsOptions' => $fsOptions, + // 'fsInstances' => $fsInstances, + // 'fsTypes' => $allFsTypes, + // 'readOnly' => $this->readOnly, + // ]) ->unless( $this->readOnly, function (CpScreenResponse $response) { diff --git a/src/Http/Resources/ElementIndexResource.php b/src/Http/Resources/ElementIndexResource.php index 2d7a15035fe..04b5974de88 100644 --- a/src/Http/Resources/ElementIndexResource.php +++ b/src/Http/Resources/ElementIndexResource.php @@ -4,6 +4,7 @@ namespace CraftCms\Cms\Http\Resources; +use CraftCms\Cms\Cp\JsonResource; use CraftCms\Cms\Element\CurrentElementIndex; use CraftCms\Cms\Http\Controllers\Elements\Concerns\InteractsWithElementIndexes; use CraftCms\Cms\Http\Requests\ElementIndexRequest; @@ -12,7 +13,6 @@ use CraftCms\Cms\Support\Facades\HtmlStack; use CraftCms\Cms\Support\Html; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\JsonResource; use Override; use function CraftCms\Cms\t; diff --git a/src/Providers/AppServiceProvider.php b/src/Providers/AppServiceProvider.php index 29725071e98..d4018d18c5d 100644 --- a/src/Providers/AppServiceProvider.php +++ b/src/Providers/AppServiceProvider.php @@ -29,7 +29,6 @@ use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Exceptions\ThrottleRequestsException; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Response; use Illuminate\Routing\UrlGenerator; use Illuminate\Support\Carbon; @@ -68,7 +67,6 @@ public function register(): void public function boot(): void { - JsonResource::withoutWrapping(); Event::listen(LocaleUpdated::class, function (LocaleUpdated $event) { setlocale( diff --git a/src/Section/Resources/SectionResource.php b/src/Section/Resources/SectionResource.php index e9c0264040a..fcb09918a9d 100644 --- a/src/Section/Resources/SectionResource.php +++ b/src/Section/Resources/SectionResource.php @@ -4,11 +4,11 @@ namespace CraftCms\Cms\Section\Resources; +use CraftCms\Cms\Cp\JsonResource; use CraftCms\Cms\Entry\Resources\EntryTypeResource; use CraftCms\Cms\Section\Data\Section; use CraftCms\Cms\Section\Enums\SectionType; use Illuminate\Http\Request; -use Illuminate\Http\Resources\Json\JsonResource; /** @mixin Section */ class SectionResource extends JsonResource