Repository navigation
Conversation
Ports 3.x's signed Cloudflare transform URLs to Craft 6's asset transform driver registry, and registers a craftCloud transformer profile that becomes the default on Cloud. Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79 Co-authored-by: Amp <amp@ampcode.com>
Core now picks transformers with a disk's asset_transformer key instead of registered profiles (craftcms/cms#20542). Register the craft-cloud driver with AssetTransformers, drop the craftCloud profile and the defaultAssetTransformer switch, and detect Cloud storage from the asset's own disk, so scoped disks work. Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1b2a5-ffcf-7312-966f-7e8624cf8b79 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In 3.x, Cloud image transforms are Cloudflare Image Resizing URLs on the asset CDN. They're signed so the Cloud gateway can verify them. In Craft 6, a disk chooses its asset transformer with an
asset_transformerkey inconfig/filesystems.php(craftcms/cms#20542). This adds acraft-cloudtransform driver for that. The URL signing scheme is unchanged, since the gateway expects it exactly.Using it. Projects set the key on their Cloud disks:
A scoped disk without the key follows the disk it wraps. A Cloud disk without the key uses Craft's own transformer, which generates transforms and stores them in the bucket. Cloud doesn't add the key or change the default for you.
What gets transformed. The driver transforms assets whose volume disk is S3 in Cloud's bucket (
CRAFT_CLOUD_PROJECT_ID). It checks the volume's own disk adapter rather than the disk'sdriverkey, so scoped disks work. It handles:avif,gif,heic,heif,jpeg,jpg,png,svgandwebp, matching the gateway's list.format=auto, and the gateway rasterizes them.Other file types throw
NotSupportedException, so the CP shows file icons. GIFs and SVGs also throw whentransformGifsortransformSvgsis off, as they do in core.Everything else goes to the
craftdriver with only the core parameters, throughtransform(..., transformer: 'craft'). That coverscraft-clouddisks in local development (where they're local disks), other S3 buckets, and temporary uploads, which aren't under the CDN's prefix. Because the driver is registered in every environment, the samefilesystems.phpworks locally.URLs. The base is the disk's CDN URL from
AssetsHelper::generateUrl(), with thevrev parameter removed, as in 3.x.UrlSignersigns it the same way 3.x does: HTTP Message Signatures over@pathand@query, in thesparameter, keyed byCRAFT_CLOUD_SIGNING_KEY.RequestSignercame along unchanged too; nothing uses it yet.Parameters.
CloudflareOptionsports the 3.x behavior mapping:modeandupscalemap tofit.position, or the focal point when one is set, maps togravity.letterboxwithfillmaps tobackground.jpgmaps tobaseline-jpegorjpeg, depending oninterlace.The Cloudflare options are declared as parameter rules in
definition(), so they're validated and can be used inline or on named transforms. Two differences from 3.x:InvalidAssetTransformException) instead of being dropped silently.qualityis now forwarded. 3.x ignored it, and the gateway passes it through tocf.image.Dependencies. This needs craftcms/cms#20542, which hasn't merged. For now,
craftcms/cmsrequires that PR's branch (dev-6.x-disk-owned-asset-transformers), withcraftcms/cms-assetsaliased to match, since core requires it at its own branch version. Switch both back to a tagged^6.0constraint once #20542 is released. The PR also addscraftcms/http-message-signatures,league/uri,league/uri-componentsandguzzlehttp/guzzlefor signing.Overlap with #212. Both PRs change
composer.lock, so whichever merges second needscomposer update --lock. The provider changes merge cleanly.Not ported yet: 3.x's
supportedImageFormatsoverride, which the driver doesn't need, and thecloud.getImg()Twig helper.Related issues