Commit ca098721 authored by Wim Leers's avatar Wim Leers Committed by Wim Leers
Browse files

Issue #3103682 by Wim Leers: CDN module 4.x: no new features + drop BC layers...

Issue #3103682 by Wim Leers: CDN module 4.x: no new features + drop BC layers + drop now irrelevant headers + PHP >=8.1 + Drupal >=9.4
parent ef9c12e9
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2,4 +2,5 @@ name: CDN
description: "Serves files (CSS, JS, images …) from a CDN."
type: module
package: "Web services"
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.4 || ^10
php: 8.1
+2 −26
Original line number Diff line number Diff line
@@ -6,31 +6,7 @@
 */

/**
 * Update the default settings if they are not modified by the user.
 * Force container & cache rebuild upon upgrading from 8.x-3.x to 4.x.
 */
function cdn_update_8001() {
  $cdn_settings = \Drupal::configFactory()->getEditable('cdn.settings');
  $mapping = $cdn_settings->get('mapping');
  if ($mapping['type'] === 'simple' && $mapping['conditions'] === []) {
    $cdn_settings->set('mapping.conditions', [
      'not' => [
        'extensions' => ['css', 'js'],
      ],
    ]);
    $cdn_settings->save();
  }
}

/**
 * Add the new "stream wrappers" setting, set it to its default initial value.
 */
function cdn_update_8002() {
  \Drupal::configFactory()->getEditable('cdn.settings')->set('stream_wrappers', ['public'])->save();
}

/**
 * Add the new "scheme" setting, set it to its default initial value.
 */
function cdn_update_8003() {
  \Drupal::configFactory()->getEditable('cdn.settings')->set('scheme', '//')->save();
function cdn_update_9401() {
}
+2 −42
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\cdn\CdnSettings;
use Drupal\editor\Entity\Editor;

/**
@@ -30,47 +31,6 @@ function cdn_help($route_name, RouteMatchInterface $route_match) {
  }
}

/**
 * Implements hook_file_url_alter().
 */
function cdn_file_url_alter(&$uri) {
  // Gracefully handle invalid invocations of file_create_url().
  // @todo Remove when requiring Drupal 9.3.
  // @see https://www.drupal.org/project/drupal/issues/2669074
  if (empty($uri) || !is_string($uri)) {
    \Drupal::logger('php')->warning('A caller of file_create_url() did not pass a file URI.');
    return;
  }
  // Don't alter file URLs when running update.php.
  // @todo Remove the second condition after the CDN module requires the Drupal core minor that ships with https://www.drupal.org/project/drupal/issues/2969056
  if (defined('MAINTENANCE_MODE') || stripos($_SERVER['PHP_SELF'], 'update.php') !== FALSE) {
    return;
  }

  // Don't alter CSS file URLs while settings.php is disabling CSS aggregation.
  if (substr($uri, -4) === '.css' && isset($GLOBALS['config']['system.performance']['css']['preprocess']) && $GLOBALS['config']['system.performance']['css']['preprocess'] === FALSE) {
    return;
  }

  // Don't serve CKEditor from a CDN when far future future is enabled (CKEditor
  // insists on computing other assets to load based on this URL).
  if ($uri === 'core/assets/vendor/ckeditor/ckeditor.js' && \Drupal::service('cdn.settings')->farfutureIsEnabled()) {
    return;
  }

  // Don't alter file URLs while processing a CSS file.
  // @see \Drupal\cdn\Asset\CssOptimizer
  global $_cdn_in_css_file;
  if ($_cdn_in_css_file) {
    return;
  }

  $result = \Drupal::service('cdn.file_url_generator')->generate($uri);
  if ($result) {
    $uri = $result;
  }
}

/**
 * Implements hook_editor_js_settings_alter().
 */
@@ -81,7 +41,7 @@ function cdn_editor_js_settings_alter(array &$settings) {

  // Don't serve CKEditor plugins from a CDN when far future future is enabled
  // (CKEditor insists on computing other assets to load based on these URLs).
  if (!\Drupal::service('cdn.settings')->farfutureIsEnabled()) {
  if (!\Drupal::service(CdnSettings::class)->farfutureIsEnabled()) {
    return;
  }

+1 −11
Original line number Diff line number Diff line
# 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+
cdn.farfuture_scheme.download:
  path: '/cdn/ff/{security_token}/{mtime}/{scheme}'
  defaults:
    _controller: cdn.controller.farfuture:downloadByScheme
    _controller: Drupal\cdn\CdnFarfutureController:download
    # Ensure the redirect module does not redirect to add a language prefix.
    # @see \Drupal\redirect\EventSubscriber\RouteNormalizerRequestSubscriber
    # @todo Update this comment when https://www.drupal.org/project/drupal/issues/2641118 lands.
+18 −17
Original line number Diff line number Diff line
services:
  cdn.settings:
    class: Drupal\cdn\CdnSettings
  Drupal\cdn\CdnSettings:
    arguments: ['@config.factory']

  cdn.file_url_generator:
    class: Drupal\cdn\File\FileUrlGenerator
    arguments: ['%app.root%', '@stream_wrapper_manager', '@request_stack', '@private_key', '@cdn.settings']
  Drupal\cdn\File\FileUrlGenerator:
    public: false
    decorates: file_url_generator
    arguments:
      - '@Drupal\cdn\File\FileUrlGenerator.inner'
      - '%app.root%'
      - '@stream_wrapper_manager'
      - '@request_stack'
      - '@private_key'
      - '@Drupal\cdn\CdnSettings'

  # Event subscribers.
  cdn.config_subscriber:
    class: Drupal\cdn\EventSubscriber\ConfigSubscriber
  Drupal\cdn\EventSubscriber\ConfigSubscriber:
    arguments: ['@cache_tags.invalidator', '@config.typed', '@kernel', '@config.installer']
    tags:
      - { name: event_subscriber }
  cdn.html_response_subscriber:
    class: Drupal\cdn\EventSubscriber\HtmlResponseSubscriber
    arguments: ['@cdn.settings']
  Drupal\cdn\EventSubscriber\HtmlResponseSubscriber:
    autowire: true
    tags:
      - { name: event_subscriber }

  # Controllers.
  cdn.controller.farfuture:
    class: \Drupal\cdn\CdnFarfutureController
  Drupal\cdn\CdnFarfutureController:
    arguments: ['@private_key', '@stream_wrapper_manager']

  # Inbound path processor for the cdn.farfuture.download route, since the
@@ -30,14 +33,12 @@ services:
  # - http://symfony.com/doc/2.8/routing/slash_in_parameter.html
  # - http://drupal.stackexchange.com/questions/175758/slashes-in-single-route-parameter-or-other-ways-to-handle-a-menu-tail-with-dynam
  # - https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tail_to_arg/7.x
  path_processor.cdn:
    class: Drupal\cdn\PathProcessor\CdnFarfuturePathProcessor
  Drupal\cdn\PathProcessor\CdnFarfuturePathProcessor:
    tags:
      - { name: path_processor_inbound }

  # Decorators.
  cdn.asset.css.optimizer:
  Drupal\cdn\Asset\CssOptimizer:
    public: false
    class: Drupal\cdn\Asset\CssOptimizer
    decorates: asset.css.optimizer
    arguments: ['@cdn.asset.css.optimizer.inner']
    arguments: ['@Drupal\cdn\Asset\CssOptimizer.inner']
Loading