Skip to content

Commit

Permalink
Send DefineAssetUrlEvent from Asset::EVENT_BEFORE_DEFINE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 6, 2023
1 parent 053d711 commit 2c5291f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed a bug where users were “View other users’ drafts” section permissions weren’t being enforced for unpublished drafts.
- Fixed a bug where element editors were showing provisional changes, even if the user didn’t have permission to save them.
- `craft\elements\Asset::EVENT_BEFORE_DEFINE_URL` now sends a `craft\events\DefineAssetUrlEvent` object, rather than `craft\events\DefineUrlEvent`. ([#13018](https://github.com/craftcms/cms/issues/13018))
- `craft\web\View::renderObjectTemplate()` now trims the returned template output.
- Fixed XSS vulnerabilities.

Expand Down
13 changes: 11 additions & 2 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use craft\errors\VolumeException;
use craft\events\AssetEvent;
use craft\events\DefineAssetUrlEvent;
use craft\events\DefineUrlEvent;
use craft\events\GenerateTransformEvent;
use craft\fieldlayoutelements\assets\AltField;
use craft\fs\Temp;
Expand Down Expand Up @@ -140,6 +139,13 @@ class Asset extends Element
*/
public const EVENT_AFTER_GENERATE_TRANSFORM = 'afterGenerateTransform';

/**
* @event DefineAssetUrlEvent The event that is triggered before defining the asset’s URL.
* @see getUrl()
* @since 4.4.7
*/
public const EVENT_BEFORE_DEFINE_URL = 'beforeDefineUrl';

/**
* @event DefineAssetUrlEvent The event that is triggered when defining the asset’s URL.
* @see getUrl()
Expand Down Expand Up @@ -1829,7 +1835,10 @@ public function getUrl(mixed $transform = null, ?bool $immediately = null): ?str
}

// Give plugins/modules a chance to provide a custom URL
$event = new DefineUrlEvent();
$event = new DefineAssetUrlEvent([
'transform' => $transform,
'asset' => $this,
]);
$this->trigger(self::EVENT_BEFORE_DEFINE_URL, $event);
$url = $event->url;

Expand Down

0 comments on commit 2c5291f

Please sign in to comment.