Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added callback to manipulate FileAdder when performing a copy #3658

Merged
merged 5 commits into from
Jul 2, 2024

Conversation

chrispage1
Copy link
Contributor

@chrispage1 chrispage1 commented Jul 2, 2024

This feature adds the ability to customise the FileAdder options when performing a copy action.

In my case, the requirement for this is to set properties against the media item, but it gives the user access to all of the FileAdder methods. Example:

use Spatie\MediaLibrary\MediaCollections\FileAdder;;

$media->copy(
    $postModel,
    fileAdderCallback: fn (FileAdder $adder): FileAdder => $adder->withProperties([
        'duplicate_of' => $oldMedia->getKey(),
    ])
);

Thanks!

@freekmurze freekmurze merged commit c3828e7 into spatie:main Jul 2, 2024
9 checks passed
@freekmurze
Copy link
Member

Thank you!

@chrispage1 chrispage1 deleted the feature/copy-callback branch July 8, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants