#3071814: Drupal 9 readiness / compatibility added Drupal 9 compatibility. We don't need a new major version for that.

But over time a few pieces of backwards compatibility layers were added. Plus, the browser landscape changed. Finally, core infrastructure improvements would allow this module to become simpler.

Browser landscape
#3100868: Remove `no-transform` directive from Far Future's `Cache-Control` header to allow CDNs to optimize assets
preconnect vs dns-prefetch: @todo Remove when http://caniuse.com/link-rel-preconnect has support in all browsers or is equivalent with http://caniuse.com/#feat=link-rel-dns-prefetch
BC layers
#2870435: Support additional stream wrappers expanded the capabilities of the CDN module, but required BC layers in \Drupal\cdn\CdnFarfutureController, \Drupal\cdn\PathProcessor\CdnFarfuturePathProcessor and cdn.routing.yml.
#3228162: Fix Drupal 9-only deprecation notices while retaining Drupal 8 compatibility added a BC layer to remain compatible with Drupal 8 while fixing Drupal 10 deprecations.
#3194164: Harden against invalid calls to file_create_url(): avoid TypeError in CDN module's code execution added a warning that is obsolete once sites are on Drupal 9.3, because core will be just as strict as the CDN module. We should remove that gracefully warning logging.
Evidently we can also remove the 8.x-3.x hook_update_N() update hooks plus the associated tests.
PHP landscape
✅ Require PHP 8.1 since Drupal 10 will require it (up from 8.0 since #3264819: Require PHP 8.1 for Drupal 10.0.0-alpha2) and active support for PHP 7.4 will end at the end of 2021. (Version 3 of the CDN module will have been around for 5 years, I'd rather make version 4 be supportable for the next 5 years.)
✅ Start using PHP 8-only features, or features that were only available in later PHP 7 versions. For example: return type hints, union types would both help make this module behave more reliably.
✅ Start using PHP 8.1-only features: https://www.php.net/releases/8.1/en.php.
Core infrastructure improvements
#2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it
#3021803: Document and add tests for service autowiring
Core infrastructure changes
#3216302: Remove Tour support
✅ Fix deprecation: Parameter $event of method Drupal​\​cdn​\​EventSubscriber​\​HtmlResponseSubscriber::onRespond() has typehint with deprecated class Symfony​\​Component​\​HttpKernel​\​Event​\​FilterResponseEvent: since Symfony 4.3, use ResponseEvent instead

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Title: CDN 4.x plan: no new features + drop BC layers + drop now irrelevant headers » CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers
Category: Plan » Task
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new11.21 KB

This patch already implements all the certainties. What's left is bumping the PHP version requirement plus taking advantage of that version bump.

andypost’s picture

wim leers’s picture

wim leers’s picture

wim leers’s picture

Title: CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers » CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP 8 + Drupal 9.3
Issue summary: View changes

If we make the 4.x version require Drupal >=9.0, then we can also increase the PHP version requirement to PHP 7.2 and probably even 7.3. See #3079791: Bump Drupal's minimum PHP version to 7.2 as soon as 9.0.x is branched (a higher version may be required later). That would allow us to go further than #3100598: CDN module requires Drupal >=8.8.0 ⇒ take advantage of PHP features introduced in 5.6 and 7.0 .

I'm thinking it should

  1. require Drupal 9.3 for autowiring
  2. PHP 8 since Drupal 10 will require it and active support for PHP 7.4 will end at the end of 2021. (Version 3 of the CDN module will have been around for 5 years, I'd rather make version 4 be supportable for the next 5 years.)
wim leers’s picture

wim leers’s picture

Issue summary: View changes

New:

  1. #3228162: Fix Drupal 9-only deprecation notices while retaining Drupal 8 compatibility added a BC layer to remain compatible with Drupal 8 while fixing Drupal 10 deprecations.
  2. #3216302: Remove Tour support
wim leers’s picture

Issue summary: View changes

New:

  1. #3194164: Harden against invalid calls to file_create_url(): avoid TypeError in CDN module's code execution added a warning that is obsolete once sites are on Drupal 9.3, because core will be just as strict as the CDN module. We should remove that gracefully warning logging.
wim leers’s picture

Issue summary: View changes
wim leers’s picture

StatusFileSize
new9.91 KB

Rebased #2.

Status: Needs review » Needs work

The last submitted patch, 11: 3103682-11.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new930 bytes
new9.91 KB

Rebased incorrectly.

Status: Needs review » Needs work

The last submitted patch, 13: 3103682-13.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new10.56 KB

Generated patch incorrectly… This is what I should've uploaded in #13.

wim leers’s picture

StatusFileSize
new12.27 KB

😬 Again wrong patch. Clearly I'm used to the merge request workflow at this point…

wim leers’s picture

StatusFileSize
new447 bytes
new12.71 KB
+++ b/cdn.routing.yml
@@ -1,17 +1,7 @@
-# The /cdn/farfuture route has been deprecated and is rewritten
-# in CdnFarfuturePathProcessor.
 cdn.farfuture.download:
-  path: '/cdn/farfuture/{security_token}/{mtime}'
-  defaults:
-    _controller: cdn.controller.farfuture:download
-    _disable_route_normalizer: TRUE
-  requirements:
-    _access: 'TRUE'
-    mtime: \d+

With this disappearing, #2870435-21: Support additional stream wrappers is relevant again. Just to be safe, we should clear all caches when updating. That still won't fix edge caches or reverse proxies, but hopefully 99% of sites will have been on the latest Drupal 8 release for a long time before upgrading. They've already had the chance to do so for over 2 years at this point, because https://www.drupal.org/project/cdn/releases/8.x-3.3 is the first release to include #2870435: Support additional stream wrappers.

However esoteric/edge case-y that may be, taking advantage of #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it will require a container rebuild anyway. So … let's do so.

wim leers’s picture

Issue summary: View changes
StatusFileSize
new7.72 KB
new19.93 KB

Did

Evidently we can also remove the 8.x-3.x hook_update_N() update hooks plus the associated tests.
wim leers’s picture

So … I tried using autowiring, but failed miserably:

Error: Class 'Symfony\Component\Config\Resource\ClassExistenceResource' not found in Symfony\Component\DependencyInjection\Compiler\AutowirePass->createTypeNotFoundMessage() (line 397 of /Users/wim.leers/Work/d8/vendor/symfony/dependency-injection/Compiler/AutowirePass.php).
Symfony\Component\DependencyInjection\Compiler\AutowirePass->createTypeNotFoundMessage(Object, 'argument "$config_factory" of method "Drupal\cdn\CdnSettings::__construct()"', 'cdn.settings') (Line: 388)
Symfony\Component\DependencyInjection\Compiler\AutowirePass->Symfony\Component\DependencyInjection\Compiler\{closure}() (Line: 926)
Symfony\Component\DependencyInjection\Definition->getErrors() (Line: 51)
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue(Object, 1) (Line: 82)
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue(Array, 1) (Line: 32)
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue(Array, 1) (Line: 46)
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 1295)
Drupal\Core\DrupalKernel->compileContainer() (Line: 900)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 472)
Drupal\Core\DrupalKernel->boot() (Line: 707)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I figured that the CDN module's service specifying the type ConfigFactoryInterface makes it impossible for the autowiring to reliably figure out the concrete class.

But turns out it's worse. The service ID needs to match the class name. This is … not very useful then. This is also why Drupal core is not yet using it: #3049525: Enable service autowiring by adding interface aliases to core service definitions.

Fortunately, this is the case for at least the cdn.settings service: its FQCN is \Drupal\cdn\CdnSettings. But alas:

The website encountered an unexpected error. Please try again later.
Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot autowire service "cdn.html_response_subscriber": argument "$cdn_settings" of method "Drupal\cdn\EventSubscriber\HtmlResponseSubscriber::__construct()" references class "Drupal\cdn\CdnSettings" but no such service exists. You should maybe alias this class to the existing "cdn.settings" service. in Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() (line 54 of /Users/wim.leers/Work/d8/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php).
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue(Object, 1) (Line: 82)
…
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

So … in the end … I was able to autowire a single service: the only service that depends only on CDN module-provided services… because until #3049525: Enable service autowiring by adding interface aliases to core service definitions, this will work for almost no service relying on core services!

wim leers’s picture

StatusFileSize
new3.94 KB
new23.3 KB

This makes the CDN module as ready for autowiring as it possibly can be — i.e. it makes the CDN module forward-looking.

Since the CDN module's services never were an API, it's fine for me to rename them without notice. Especially when doing a new major release.

wim leers’s picture

StatusFileSize
new14.51 KB
new35.81 KB

Now let's finally take advantage of #2669074: Convert file_create_url() & file_url_transform_relative() to service, deprecate it!

This is the minimum set of changes. There are probably refactoring opportunities now, but not yet taking action on those.

wim leers’s picture

StatusFileSize
new1.71 KB
new35.82 KB

Fix PHPCS violations.

wim leers’s picture

StatusFileSize
new713 bytes
new35.95 KB
+++ b/cdn.module
@@ -74,7 +74,7 @@ function cdn_editor_js_settings_alter(array &$settings) {
-  if (!\Drupal::service('cdn.settings')->farfutureIsEnabled()) {
+  if (!\Drupal::service('Drupal\cdn\CdnSettings')->farfutureIsEnabled()) {

#21 made this change.

(As well as a few others like this, but those have been refactored away in #22 + #23.)

The good news is that this means this use of service locator instead of dependency injection becomes less brittle, because we can use FQCN::class for it!

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Marking RTBC so we hopefully get auto-retesting…

wim leers’s picture

Title: CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP 8 + Drupal 9.3 » CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP >=8 + Drupal >=9.3
wim leers’s picture

StatusFileSize
new326 bytes
new36.33 KB

Oh, and do what the issue title says: require PHP >=8 and Drupal >=9.3 (including Drupal 10!).

wim leers’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

https://dev.acquia.com/drupal10/deprecation_status/errors?name=cdn%203.x... shows:

Parameter $event of method Drupal​\​cdn​\​EventSubscriber​\​HtmlResponseSubscriber::onRespond() has typehint with deprecated class Symfony​\​Component​\​HttpKernel​\​Event​\​FilterResponseEvent: since Symfony 4.3, use ResponseEvent instead

That's one more thing we should fix here.

wim leers’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.07 KB
new37.16 KB
wim leers’s picture

Issue summary: View changes
wim leers’s picture

Note: Drupal 10 might require PHP 8.1: #3223435: Track PHP 8.1 support in hosting and distributions.

wim leers’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
wim leers’s picture

Title: CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP >=8 + Drupal >=9.3 » CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP >=8.1 + Drupal >=9.3
wim leers’s picture

Note to self: all strpos(…, …) !== 0 and strpos(…, …) === 0 occurrences can also be replaced with https://www.php.net/manual/en/function.str-starts-with.php.

wim leers’s picture

I wrote this in #20:

But turns out it's worse. The service ID needs to match the class name. This is … not very useful then. This is also why Drupal core is not yet using it: #3049525: Enable service autowiring by adding interface aliases to core service definitions

Good news! #3049525: Enable service autowiring by adding interface aliases to core service definitions just landed in 10.0.x, during RC! 🤩

wim leers’s picture

wim leers’s picture

Status: Needs work » Postponed
wim leers’s picture

Status: Active » Needs review
StatusFileSize
new36.57 KB

Rerolled #29 on top of the changes mentioned in #38.

wim leers’s picture

Title: CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP >=8.1 + Drupal >=9.3 » CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP >=8.1 + Drupal >=9.4
Issue summary: View changes
StatusFileSize
new408 bytes
new36.57 KB

Requiring PHP >=8.1 and Drupal >=9.4

wim leers’s picture

StatusFileSize
new20.22 KB
new51.76 KB

Adopt PHP 8.1-only features.

wim leers’s picture

Issue summary: View changes
wim leers’s picture

StatusFileSize
new2.23 KB
new51.68 KB

Ran into Symfony's less-than-stellar MASTER_REQUEST-to-MAIN_REQUEST transition again, as described in #3296639-19: Drupal 10 compatibility… 😬

wim leers’s picture

Version: 8.x-3.x-dev » 4.x-dev
wim leers’s picture

StatusFileSize
new1.78 KB
new55.11 KB

One more oversight — an update test fixture that is obsolete.

  • Wim Leers committed ca09872 on 4.x
    Issue #3103682 by Wim Leers: CDN module 4.x: no new features + drop BC...
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.