Skip to content

Commit

Permalink
Merge pull request #4213 from benface/replaced-assets-filename
Browse files Browse the repository at this point in the history
Allow plugins and modules to change the filename of replaced assets
  • Loading branch information
andris-sevcenko authored May 8, 2019
2 parents 38cd5aa + 4590db1 commit 4921d5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changed
- Craft now stores the Default User Group’s UID in the project config, in case the group’s ID is different across environments.
- `craft\services\Assets::EVENT_BEFORE_REPLACE_ASSET` event handlers can now change the filename of the replaced asset before it is saved.
- Improved the performance of background jobs. ([#4219](https://github.com/craftcms/cms/pull/4219))
- Improved the Plugin Store’s screenshots with arrows for navigation and pinch-to-zoom capability for touch devices.

Expand Down
6 changes: 4 additions & 2 deletions src/services/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ public function replaceAssetFile(Asset $asset, string $pathOnServer, string $fil
{
// Fire a 'beforeReplaceFile' event
if ($this->hasEventHandlers(self::EVENT_BEFORE_REPLACE_ASSET)) {
$this->trigger(self::EVENT_BEFORE_REPLACE_ASSET, new ReplaceAssetEvent([
$event = new ReplaceAssetEvent([
'asset' => $asset,
'replaceWith' => $pathOnServer,
'filename' => $filename
]));
]);
$this->trigger(self::EVENT_BEFORE_REPLACE_ASSET, $event);
$filename = $event->filename;
}

$asset->tempFilePath = $pathOnServer;
Expand Down

0 comments on commit 4921d5d

Please sign in to comment.