From 81dc1b0b93e4cf6e51192409f37c97d9d9e55c69 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 30 Jan 2026 10:45:44 -0500 Subject: [PATCH] backport --- .../fieldtypes/assets/AssetsIndexFieldtype.vue | 8 +++++++- src/Fieldtypes/Assets/Assets.php | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/resources/js/components/fieldtypes/assets/AssetsIndexFieldtype.vue b/resources/js/components/fieldtypes/assets/AssetsIndexFieldtype.vue index fa9111204f4..4ec80ebe477 100644 --- a/resources/js/components/fieldtypes/assets/AssetsIndexFieldtype.vue +++ b/resources/js/components/fieldtypes/assets/AssetsIndexFieldtype.vue @@ -2,13 +2,19 @@
+ + + {{ value.total - 5 }} +
diff --git a/src/Fieldtypes/Assets/Assets.php b/src/Fieldtypes/Assets/Assets.php index 3e4adc99854..0e1999d9afd 100644 --- a/src/Fieldtypes/Assets/Assets.php +++ b/src/Fieldtypes/Assets/Assets.php @@ -345,7 +345,16 @@ public function fieldRules() public function preProcessIndex($data) { - return $this->getItemsForPreProcessIndex($data)->map(function ($asset) { + $total = $data === null + ? 0 + : ($this->config('max_files') === 1 ? 1 : count($data)); + + // Since we only want to display a handful of thumbnails, we'll slice it up here so we don't perform more + // augmentation overhead than necessary. e.g. 5 thumbs then +remainder. If the remainder is 1, we may + // as well show all 6 since the +1 would almost take up the same amount of space. + $data = collect($data)->take(6)->all(); + + $assets = $this->getItemsForPreProcessIndex($data)->map(function ($asset) { $arr = [ 'id' => $asset->id(), 'is_image' => $isImage = $asset->isImage(), @@ -363,6 +372,8 @@ public function preProcessIndex($data) return $arr; }); + + return compact('total', 'assets'); } protected function getItemsForPreProcessIndex($values): Collection