Additional event after generating asset URLs #8784
Replies: 4 comments
-
Can you give me an example of what you are hoping to achieve with the event? |
Beta Was this translation helpful? Give feedback.
-
A concrete example are Signed URLs for AWS Cloudfront, where we have to add additional query parameters to the generated URL. |
Beta Was this translation helpful? Give feedback.
-
Wow, seems like it's been a long time since the transform service has been refactored. The core problem with this is that there are several return points when generating the URL. And if we add an event to modify the URL, it should work for ALL Asset URLs, whether you're returning the URL by requesting it from the Asset element itself or whether it's by asking the Asset service. In a similar vein, it should work whenever the URL is generated, so, if setting So I'm refactoring some bits and moving code around. I'll let you know when it's done! |
Beta Was this translation helpful? Give feedback.
-
Hey @kringkaste, we’re mulling over the best approach here, and it’s looking like we may need to hold off on this until Craft 4 so we’re not introducing any breaking changes for volume type plugins. So in the meantime, I’d suggest you just add your additional params using the url() function: {{ url(asset.url, {foo: 'bar'}) }} (You could move that to a macro that accepts the asset object as an argument, to keep your templates DRY.) |
Beta Was this translation helpful? Give feedback.
-
Hi!
I would be interested to know what you would think of the following enhancement: To allow plugins to customize the URL of an asset after it has been generated in the function
Assets::getAssetUrl()
, it would be useful to add another event that is triggered after the URL is generated.I know the limitation would be, that this only works if
$generateNow == true
, but this way e.g. volume plugins could add storage specific parameters without having to duplicate the normal behavior of assets.Maybe I missed something and there is already some other way to make this possible, but an additional event would be the most flexible (also for other types of plugins).
What do you think? I would make a pull request for this, if this has a chance of being approved by you.
Cheers,
Thomas
Beta Was this translation helpful? Give feedback.
All reactions