Skip to content

Commit

Permalink
Copy media with manipulations (#3590)
Browse files Browse the repository at this point in the history
MrMeshok authored Apr 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4557739 commit 85f5f82
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/MediaCollections/Models/Media.php
Original file line number Diff line number Diff line change
@@ -407,6 +407,7 @@ public function copy(HasMedia $model, $collectionName = 'default', string $diskN
->addMedia($temporaryFile)
->usingName($this->name)
->setOrder($this->order_column)
->withManipulations($this->manipulations)
->withCustomProperties($this->custom_properties);
if ($fileName !== '') {
$fileAdder->usingFileName($fileName);
15 changes: 15 additions & 0 deletions tests/Feature/Media/CopyTest.php
Original file line number Diff line number Diff line change
@@ -148,3 +148,18 @@
expect($media->getPath())->toBeFile();
expect($anotherMedia->getPath())->toBeFile();
});

it('can copy media with manipulations', function () {
$model = TestModel::create(['name' => 'original']);

$media = $model
->addMedia($this->getTestJpg())
->withManipulations(['thumb' => ['greyscale' => [], 'height' => [10]]])
->toMediaCollection();

$anotherModel = TestModel::create(['name' => 'target']);

$anotherMedia = $media->copy($anotherModel);

expect($media->manipulations)->toEqual($anotherMedia->manipulations);
});

0 comments on commit 85f5f82

Please sign in to comment.