1

Admin users can replace asset files without having to deal with re-uploading/re-creating a new asset using the feature/technique described in Peter's answer here: Is it possible to replace uploaded assets?. This has the advantage of preserving any values in the asset's custom fields.

I need to populate some of those fields dynamically though, so they correspond to the new file for the asset. So, I wrote a small plugin that listens to the assets.onReplaceFile event like so:

craft()->on('assets.replaceFile', function(Event $event) {
  Craft::dd($event->params); // or whatever
});

But the code in the handler never gets executed. Is this the right event to listen to this specific user action or is there another event for it? Or am I doing something wrong here? Thanks!

  • Where does that code live? In your plugin's init() method? – Brad Bell Nov 10 '16 at 23:54
  • Yes, in the init() method of the plugin's main class. – yoannisj Nov 12 '16 at 17:18
  • Can you describe the workflow you're using where you're expecting the event to get fired? – Brad Bell Nov 13 '16 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.