Skip to content
Snippets Groups Projects
Commit b80a6664 authored by Dieter Holvoet's avatar Dieter Holvoet Committed by Lisa Harrison
Browse files

Issue #3376399: Override new lazy asset collection optimizers

parent 5e9889c2
No related branches found
No related tags found
1 merge request!26Issue #3376399: Override new lazy asset collection optimizers
<?php
namespace Drupal\flysystem\Asset;
use Drupal\Core\Asset\CssCollectionOptimizerLazy as DrupalCssCollectionOptimizerLazy;
use Drupal\Core\File\Exception\FileException;
/**
* Optimizes CSS assets.
*/
class CssCollectionOptimizerLazy extends DrupalCssCollectionOptimizerLazy {
use SchemeExtensionTrait;
/**
* {@inheritdoc}
*/
public function deleteAll() {
$this->state->delete('drupal_css_cache_files');
try {
$this->fileSystem->deleteRecursive($this->getSchemeForExtension('css') . '://css');
} catch (FileException $fileException) {
\Drupal::logger('flysystem')->error($fileException->getMessage());
}
}
}
<?php
namespace Drupal\flysystem\Asset;
use Drupal\Core\Asset\JsCollectionOptimizerLazy as DrupalJsCollectionOptimizerLazy;
use Drupal\Core\File\Exception\FileException;
/**
* Optimizes JavaScript assets.
*/
class JsCollectionOptimizerLazy extends DrupalJsCollectionOptimizerLazy {
use SchemeExtensionTrait;
/**
* {@inheritdoc}
*/
public function deleteAll() {
$this->state->delete('system.js_cache_files');
try {
$this->fileSystem->deleteRecursive($this->getSchemeForExtension('js') . '://js');
} catch (FileException $fileException) {
\Drupal::logger('flysystem')->error($fileException->getMessage());
}
}
}
......@@ -3,6 +3,7 @@
namespace Drupal\flysystem\Asset;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\AssetsStream;
/**
* Flysystem dependency injection container.
......@@ -19,11 +20,14 @@ trait SchemeExtensionTrait {
* The scheme that should serve the extension.
*/
public function getSchemeForExtension($extension) {
$has_assets_scheme = class_exists(AssetsStream::class);
$extension_scheme = 'public';
foreach (Settings::get('flysystem', []) as $scheme => $configuration) {
if (!empty($configuration['serve_' . $extension]) && !empty($configuration['driver'])) {
if ($has_assets_scheme) {
@trigger_error(sprintf('The serve_%s Flysystem option is deprecated in flysystem:2.1.0 and is removed from flysystem:3.0.0. Use the assets:// stream wrapper instead. See https://www.drupal.org/node/3328126', $extension), E_USER_DEPRECATED);
}
// Don't break, the last configured one will win.
$extension_scheme = $scheme;
}
......
......@@ -68,9 +68,14 @@ class FlysystemServiceProvider implements ServiceProviderInterface {
$container
->getDefinition('asset.' . $extension . '.dumper')
->setClass('Drupal\flysystem\Asset\AssetDumper');
$container
->getDefinition('asset.' . $extension . '.collection_optimizer')
->setClass('Drupal\flysystem\Asset\\' . ucfirst($extension) . 'CollectionOptimizer');
$optimizer = $container->getDefinition('asset.' . $extension . '.collection_optimizer');
if ($optimizer->getClass() === 'Drupal\Core\Asset\\' . ucfirst($extension) . 'CollectionOptimizer') {
$optimizer->setClass('Drupal\flysystem\Asset\\' . ucfirst($extension) . 'CollectionOptimizer');
}
if ($optimizer->getClass() === 'Drupal\Core\Asset\\' . ucfirst($extension) . 'CollectionOptimizerLazy') {
$optimizer->setClass('Drupal\flysystem\Asset\\' . ucfirst($extension) . 'CollectionOptimizerLazy');
}
if ($extension === 'css') {
$container
......
......@@ -50,6 +50,10 @@ class LocalPathProcessor implements InboundPathProcessorInterface {
$rest = substr($path, strlen($this->root) + 2);
if (preg_match('#^(js|css)/#', $rest)) {
return $path;
}
if (strpos($rest, 'styles/') === 0 && substr_count($rest, '/') >= 3) {
[, $image_style, $scheme, $file] = explode('/', $rest, 4);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment