From ed154b846b1e786746a0a55d02554aa3d7b05f80 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 28 Aug 2024 08:13:29 +0100 Subject: [PATCH 1/3] only validate visible fields --- src/fields/Assets.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fields/Assets.php b/src/fields/Assets.php index 2ef87beee4c..0e454d020b8 100644 --- a/src/fields/Assets.php +++ b/src/fields/Assets.php @@ -242,11 +242,23 @@ protected function defineRules(): array [ 'sources', 'defaultUploadLocationSource', - 'restrictedLocationSource', 'defaultUploadLocationSubpath', + ], + 'validateNotTempVolume', + 'when' => function(self $field): bool { + return (bool)$field->restrictLocation === false; + }, + ]; + + $rules[] = [ + [ + 'restrictedLocationSource', 'restrictedLocationSubpath', ], 'validateNotTempVolume', + 'when' => function(self $field): bool { + return (bool)$field->restrictLocation; + }, ]; $rules[] = [['previewMode'], 'in', 'range' => [self::PREVIEW_MODE_FULL, self::PREVIEW_MODE_THUMBS], 'skipOnEmpty' => false]; From 20432f56a06aec8f5537bff573716b79518fb4f0 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 28 Aug 2024 11:15:18 -0700 Subject: [PATCH 2/3] Cleanup --- src/fields/Assets.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/fields/Assets.php b/src/fields/Assets.php index 0e454d020b8..c5f1754b071 100644 --- a/src/fields/Assets.php +++ b/src/fields/Assets.php @@ -245,9 +245,7 @@ protected function defineRules(): array 'defaultUploadLocationSubpath', ], 'validateNotTempVolume', - 'when' => function(self $field): bool { - return (bool)$field->restrictLocation === false; - }, + 'when' => fn() => !$this->restrictLocation, ]; $rules[] = [ @@ -256,9 +254,7 @@ protected function defineRules(): array 'restrictedLocationSubpath', ], 'validateNotTempVolume', - 'when' => function(self $field): bool { - return (bool)$field->restrictLocation; - }, + 'when' => fn() => $this->restrictLocation, ]; $rules[] = [['previewMode'], 'in', 'range' => [self::PREVIEW_MODE_FULL, self::PREVIEW_MODE_THUMBS], 'skipOnEmpty' => false]; From fadfc23a7fdc21287c25daab803d9e782a3a03ca Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 28 Aug 2024 11:16:42 -0700 Subject: [PATCH 3/3] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aecd9db096b..facb46c3eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed a SQL error that occurred when running the `db/convert-charset` command if there were any custom database views or sequences. ([#15598](https://github.com/craftcms/cms/issues/15598)) - Fixed a bug where `craft\helpers\Db::supportsTimeZones()` could return `false` on databases that supported time zone conversion. ([#15592](https://github.com/craftcms/cms/issues/15592)) +- Fixed a bug where Assets fields were validating settings that weren’t applicable depending on the “Restrict assets to a single location” setting. ([#15545](https://github.com/craftcms/cms/issues/15545)) ## 4.11.5 - 2024-08-26