From 8e72265aa222cbff982eb124f8e01f77ea137f7f Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Fri, 19 May 2023 11:29:14 +0100 Subject: [PATCH 1/6] Render URL / Has URL fields in FS template --- src/base/Fs.php | 18 ++++++ src/base/FsTrait.php | 10 +++ src/controllers/FsController.php | 2 - src/templates/settings/filesystems/_edit.twig | 62 ++++++++++++------- 4 files changed, 67 insertions(+), 25 deletions(-) diff --git a/src/base/Fs.php b/src/base/Fs.php index ec851b3b0c2..c665c3f10bb 100644 --- a/src/base/Fs.php +++ b/src/base/Fs.php @@ -29,6 +29,24 @@ abstract class Fs extends SavableComponent implements FsInterface public const VISIBILITY_HIDDEN = 'hidden'; public const VISIBILITY_PUBLIC = 'public'; + /** + * @inheritdoc + * + * TODO: remove for Craft 5 and fully move $hasUrl and $url to FS settings + */ + public function getSettings(): array + { + $settings = parent::getSettings(); + + // url should keep being saved top-level, not inside settings + // to be changed in Craft 5 + if (isset($settings['url']) && $this->url === $settings['url']) { + unset($settings['url']); + } + + return $settings; + } + /** * @inheritdoc */ diff --git a/src/base/FsTrait.php b/src/base/FsTrait.php index 7946f4099d4..23d5cac1ba8 100644 --- a/src/base/FsTrait.php +++ b/src/base/FsTrait.php @@ -44,4 +44,14 @@ trait FsTrait * @var string|null UID */ public ?string $uid = null; + + /** + * @var bool Whether to show the toggle for setting if the volume has a public URL + */ + public bool $showHasUrlSetting = true; + + /** + * @var bool Whether to show the input for setting the volume's URL + */ + public bool $showUrlSetting = true; } diff --git a/src/controllers/FsController.php b/src/controllers/FsController.php index c3c5409c51b..0294dc27607 100644 --- a/src/controllers/FsController.php +++ b/src/controllers/FsController.php @@ -140,8 +140,6 @@ public function actionSave(): ?YiiResponse 'name' => $this->request->getBodyParam('name'), 'handle' => $this->request->getBodyParam('handle'), 'oldHandle' => $this->request->getBodyParam('oldHandle'), - 'hasUrls' => (bool)$this->request->getBodyParam('hasUrls'), - 'url' => $this->request->getBodyParam('url'), 'settings' => $this->request->getBodyParam("types.$type"), ]); diff --git a/src/templates/settings/filesystems/_edit.twig b/src/templates/settings/filesystems/_edit.twig index 0469fe07ae8..425ea984fec 100644 --- a/src/templates/settings/filesystems/_edit.twig +++ b/src/templates/settings/filesystems/_edit.twig @@ -1,4 +1,5 @@ {% import '_includes/forms.twig' as forms %} +{% import _self as macro %} {% if oldHandle %}{{ hiddenInput('oldHandle', oldHandle) }}{% endif %} @@ -26,29 +27,6 @@ required: true, }) }} -{{ forms.lightswitchField({ - label: 'Files in this filesystem have public URLs'|t('app'), - name: 'hasUrls', - on: filesystem.hasUrls, - toggle: "url-field" -}) }} - -
- {{ forms.autosuggestField({ - label: "Base URL"|t('app'), - instructions: "The base URL to the files in this filesystem."|t('app'), - id: 'url', - class: ['ltr', 'fs-url'], - name: 'url', - suggestEnvVars: true, - suggestAliases: true, - value: (filesystem is defined ? filesystem.url : null), - errors: (filesystem is defined ? filesystem.getErrors('url') : null), - required: true, - placeholder: "//example.com/path/to/folder" - }) }} -
-
{% if fsOptions|length %} @@ -69,8 +47,16 @@