Skip to content

Commit

Permalink
Side-step an issue which caused Craft 4.4.x to do unwanted image tran…
Browse files Browse the repository at this point in the history
…sform work even when using an external service to do the transforms ([#373](#373)) ([#13018](craftcms/cms#13018))
  • Loading branch information
khalwat committed Apr 6, 2023
1 parent 33ad2c0 commit bef35ad
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ImageOptimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,23 @@ protected function installEventHandlers(): void
*/
protected function installAssetEventHandlers(): void
{
// Handler: Assets::EVENT_GET_ASSET_URL
// Use Asset::EVENT_BEFORE_DEFINE_URL if it's available
// ref: https://github.com/craftcms/cms/issues/13018
try {
$ref = new \ReflectionClassConstant(Asset::class, 'EVENT_BEFORE_DEFINE_URL');
} catch (\ReflectionException) {
$ref = null;
}
$eventName = $ref?->getDeclaringClass()->name === Asset::class
? Asset::EVENT_BEFORE_DEFINE_URL
: Asset::EVENT_DEFINE_URL;
// Handler: Assets::EVENT_DEFINE_URL
Event::on(
Asset::class,
Asset::EVENT_DEFINE_URL,
$eventName,
static function (DefineAssetUrlEvent $event): void {
Craft::debug(
'Asset::EVENT_GET_ASSET_URL',
'Asset::EVENT_DEFINE_URL',
__METHOD__
);
// Return the URL to the asset URL or null to let Craft handle it
Expand Down

0 comments on commit bef35ad

Please sign in to comment.