On a fresh install of Drupal using drupal:8.6-apache Docker image, I observed the following behavior:

  • When s3fs is installed and configured with the following:
    /**
     * s3fs related config
     */
    $settings['s3fs.access_key'] = 'S3_ACCESS_KEY';
    $settings['s3fs.secret_key'] = 'S3_SECRET_KEY';
    $config['s3fs.settings']['root_folder'] = 'www-root';
    $config['s3fs.settings']['bucket'] = 'my-unique-bucket';
    $config['s3fs.settings']['use_cname'] = TRUE;
    $config['s3fs.settings']['domain'] = 'example.cloudfront.net';
    $config['s3fs.settings']['use_https'] = TRUE;
    $config['s3fs.settings']['no_rewrite_cssjs'] = TRUE;
    $settings['s3fs.use_s3_for_public'] = TRUE;
    $settings['s3fs.use_s3_for_private'] = TRUE;
    
  • When cdn module is enabled
  • When advagg is enabled

I get the following error:

TypeError: Argument 1 passed to Drupal\\s3fs\\EventSubscriber\\S3fsAdvAggSubscriber::__construct() must be an instance of Drupal\\s3fs\\Asset\\S3fsCssOptimizer, instance of Drupal\\cdn\\Asset\\CssOptimizer given, called in /var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php on line 262 in /var/www/html/modules/contrib/s3fs/src/EventSubscriber/S3fsAdvAggSubscriber.php on line 29 #0 /var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php(262): Drupal\\s3fs\\EventSubscriber\\S3fsAdvAggSubscriber->__construct(Object(Drupal\\cdn\\Asset\\CssOptimizer))\n#1 /var/www/html/core/lib/Drupal/Component/DependencyInjection/Container.php(171): Drupal\\Component\\DependencyInjection\\Container->createService(Array, 's3fs.advagg.css...')\n#2 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(105): Drupal\\Component\\DependencyInjection\\Container->get('s3fs.advagg.css...')\n#3 /var/www/html/modules/contrib/advagg/src/Asset/CssOptimizer.php(91): Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher->dispatch('advagg.optimize...', Object(Drupal\\advagg\\Asset\\AssetOptimizationEvent))\n#4 /var/www/html/modules/contrib/advagg/src/Asset/AssetOptimizer.php(226): Drupal\\advagg\\Asset\\CssOptimizer->optimizeFile(Array, Array)\n#5 /var/www/html/modules/contrib/advagg/src/Asset/AssetOptimizer.php(145): Drupal\\advagg\\Asset\\AssetOptimizer->scanFile(Array)\n#6 /var/www/html/modules/contrib/advagg/advagg.module(117): Drupal\\advagg\\Asset\\AssetOptimizer->processAssetArray(Array)\n#7 /var/www/html/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): advagg_css_alter(Array, Object(Drupal\\Core\\Asset\\AttachedAssets), NULL)\n#8 /var/www/html/core/lib/Drupal/Core/Asset/AssetResolver.php(159): Drupal\\Core\\Extension\\ModuleHandler->alter('css', Array, Object(Drupal\\Core\\Asset\\AttachedAssets))\n#9 /var/www/html/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(291): Drupal\\Core\\Asset\\AssetResolver->getCssAssets(Object(Drupal\\Core\\Asset\\AttachedAssets), false)\n#10 /var/www/html/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php(161): Drupal\\Core\\Render\\HtmlResponseAttachmentsProcessor->processAssetLibraries(Object(Drupal\\Core\\Asset\\AttachedAssets), Array)\n#11 /var/www/html/core/modules/big_pipe/src/Render/BigPipeResponseAttachmentsProcessor.php(94): Drupal\\Core\\Render\\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\\Core\\Render\\HtmlResponse))\n#12 /var/www/html/core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php(45): Drupal\\big_pipe\\Render\\BigPipeResponseAttachmentsProcessor->processAttachments(Object(Drupal\\Core\\Render\\HtmlResponse))\n#13 [internal function]: Drupal\\Core\\EventSubscriber\\HtmlResponseSubscriber->onRespond(Object(Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent), 'kernel.response', Object(Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher))\n#14 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent), 'kernel.response', Object(Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher))\n#15 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\\Component\\EventDispatcher\\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent))\n#16 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\\Component\\HttpKernel\\HttpKernel->filterResponse(Object(Drupal\\Core\\Render\\HtmlResponse), Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#18 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#19 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\\Core\\StackMiddleware\\Session->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#20 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#21 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\\page_cache\\StackMiddleware\\PageCache->pass(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#22 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\\page_cache\\StackMiddleware\\PageCache->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#23 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#24 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#25 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\\StackedHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#26 /var/www/html/index.php(19): Drupal\\Core\\DrupalKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#27 {main}, referer: http://www.iste.local/admin/reports

When the config $settings['s3fs.use_s3_for_public'] is set to FALSE or not configured or either of advagg and cdn modules are uninstalled, the error is gone.

I needed s3fs, cdn and advagg for my particular use case so I hacked away s3fs' module by the attached patch.
I am not a Drupal developer. I am a SysAdmin with a little bit of PHP knowledge.

Anyone encountered this issue?

CommentFileSizeAuthor
patch_s3fs_8.x-3.x.patch623 bytesbryancs

Issue fork s3fs-3038524

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bryancs created an issue. See original summary.

trickfun’s picture

I have the same error. the patch works fine.
thanks

subhojit777 made their first commit to this issue’s fork.

subhojit777’s picture

Instead of removing the typehint, I think we should typehint with the main structure.

  • cmlara committed 996b033 on 8.x-3.x
    Issue #3038524 by subhojit777, bryancs, trickfun, cmlara: s3fs, cdn,...
cmlara’s picture

Status: Active » Fixed

Resolved.

The typehint was actually just the tip of the issue here. We also had a further fault of that the CDN decorator does not pass rewriteFileURIBasePath() through.

Since the action we take on the S3fsAdvAggSubscriber is very specif and doesn't depend on other services removed the injection of 'asset.css.optimizer' and replace with injection of 'config.factory' to allow a direct construction of a S3fsCssOptimizer as the only feature we want is the ability to rewrite the URL's for S3.

Status: Fixed » Closed (fixed)

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