Skip to content

[4.x]: Updating Assets via GraphQL does not trigger EVENT_AFTER_REPLACE_ASSET #17005

Closed
@krafttoast

Description

@krafttoast

What happened?

Description

When updating an asset via GraphQL the EVENT_AFTER_REPLACE_ASSET is not triggered.

Steps to reproduce

  1. Upload an asset to Craft

  2. Create a module with the EVENT_AFTER_REPLACE_ASSET and just throw an Error
    Event::on( Assets::class, Assets::EVENT_AFTER_REPLACE_ASSET, function (ReplaceAssetEvent $event) { throw new Error('Some Errormsg'); } );

  3. Create a mutation with payload that replaces the Asset

mutation AssetMutation( $id: ID, $folderId: ID, $document: FileInput, $title: String, ) { save_images_Asset( _file: $document, title: $title, id: $id newFolderId: $folderId ) { id folderId title } }

Payload is the output of the following php fun

public function assetPayload(string $fileData, array $image): String { $payload = [ 'id' => $image['id'], 'folderId' => $image['folderId'], 'title' => $image['name']', 'document' => [ 'filename' => $image['name'], 'fileData' => "data:image/jpg;base64," . $fileData ], ]; return json_encode($payload); }

  1. Replace an Asset via Crafts native backend and observe an error is thrown

  2. Run the mutation for the same Asset and see no Error is thrown

Expected behavior

When updating an Asset via GraphQL the EVENT_AFTER_REPLACE_ASSET and EVENT_BEFORE_REPLACE_ASSET are triggered.

Actual behavior

Said events are not triggered.

Craft CMS version

Craft CMS 4.14.11 Pro

PHP version

PHP 8.2.22

Operating system and version

Linux 6.8.0-56-generic

Database type and version

PostgreSQL 12.14

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions