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

[4.x] Add AssetCreating, AssetCreated and AssetSaving events #9378

Conversation

ryanmitchell
Copy link
Contributor

This PR adds missing events to the Asset class - creating, created and saving.

src/Assets/Asset.php Outdated Show resolved Hide resolved
@jasonvarga
Copy link
Member

By making this change, we can avoid adding a million mock expectations:

public function save()
{
-     $isNew = is_null(Facades\Asset::find($this->id()));
+     $isNew = is_null($this->container()->asset($this->path()));

Asset::find() does a lookup for the container which we don't need to do since we already have the container.

However AssetContainer::asset() calls Asset::make() which gives a similar mock expectation error. Changing the handful of existing mocks to partial mocks sorts that out.

@jasonvarga jasonvarga merged commit 2f1214e into statamic:4.x Mar 8, 2024
18 checks passed
@ryanmitchell ryanmitchell deleted the feature/asset-saving-creating-created-events branch March 8, 2024 21:19
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.

None yet

3 participants