diff --git a/src/MediaCollections/Models/Collections/MediaCollection.php b/src/MediaCollections/Models/Collections/MediaCollection.php index 0484f5ec7..1a2296492 100644 --- a/src/MediaCollections/Models/Collections/MediaCollection.php +++ b/src/MediaCollections/Models/Collections/MediaCollection.php @@ -52,17 +52,19 @@ public function toHtml() public function jsonSerialize() { - return old($this->formFieldName ?? $this->collectionName) ?? $this->map(function (Media $media) { - return [ - 'name' => $media->name, - 'file_name' => $media->file_name, - 'uuid' => $media->uuid, - 'preview_url' => $media->hasGeneratedConversion('preview') ? $media->getUrl('preview') : '', - 'order' => $media->order_column, - 'custom_properties' => $media->custom_properties, - 'extension' => $media->extension, - 'size' => $media->size, - ]; + return ($this->formFieldName ?? $this->collectionName) + ? old($this->formFieldName ?? $this->collectionName) + : $this->map(function (Media $media) { + return [ + 'name' => $media->name, + 'file_name' => $media->file_name, + 'uuid' => $media->uuid, + 'preview_url' => $media->hasGeneratedConversion('preview') ? $media->getUrl('preview') : '', + 'order' => $media->order_column, + 'custom_properties' => $media->custom_properties, + 'extension' => $media->extension, + 'size' => $media->size, + ]; })->keyBy('uuid'); } }