Event for detecting Asset File Change #9717
-
Hi, is there a way to detect when the file of an asset has been changed? I was looking at I also found Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can check the asset’s scenario from use craft\elements\Asset;
use craft\events\ModelEvent;
use yii\base\Event;
Event::on(Asset::class, Asset::EVENT_AFTER_SAVE, function(ModelEvent $event) {
/** @var Asset $asset */
$asset = $event->sender;
$scenario = $asset->getScenario();
if (in_array($asset->getScenario(), [
Asset::SCENARIO_CREATE,
Asset::SCENARIO_MOVE,
Asset::SCENARIO_REPLACE,
Asset::SCENARIO_FILEOPS,
])) {
// something is happening with the actual file
}
}); |
Beta Was this translation helpful? Give feedback.
You can check the asset’s scenario from
EVENT_AFTER_SAVE
to get an idea of what’s happening with the file.