Skip to content
Snippets Groups Projects

Support overriding assets:// in core

2 files
+ 20
2
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 19
0
@@ -3,7 +3,9 @@
namespace Drupal\flysystem;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\Util;
use Codementality\FlysystemStreamWrapper\FlysystemStreamWrapper;
@@ -69,6 +71,23 @@ class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInt
* {@inheritdoc}
*/
public function getExternalUrl() {
// Assets is a special case as Drupal generates these on the fly, similar
// to how image styles have historically operated. This requires Drupal to
// always be inline of this request. On repeat visits, the asset will be
// piped through to the client, but this is not as fast as serving directly
// from disk or worse, from object storage over the network. Sites wishing
// to offload serving the generated assets should consider pairing Flysystem
// with CDN module and treating these assets as "far-future" URLs.
if (StreamWrapperManager::getScheme($this->uri) === 'assets') {
$target = $this->getTarget($this->uri);
return Url::fromRoute(
sprintf('system.%s_asset', current(explode(DIRECTORY_SEPARATOR, $target, 2))),
// @todo Use Drupal's FileSystem::basename() if we can make it static.
['file_name' => basename($target)],
)
->toString(TRUE)
->getGeneratedUrl();
}
return $this
->getFactory()
->getPlugin($this->getProtocol())
Loading