Problem/Motivation
After updating Drupal 10.2.7 to 10.3.0 get a PHP Fatal error:
PHP Fatal error: Declaration of Drupal\tinypng\Controller\TinyPngImageStyleDownloadController::deliver(Symfony\Component\HttpFoundation\Request $request, $scheme, Drupal\image\ImageStyleInterface $image_style) must be compatible with Drupal\image\Controller\ImageStyleDownloadController::deliver(Symfony\Component\HttpFoundation\Request $request, $scheme, Drupal\image\ImageStyleInterface $image_style, string $required_derivative_scheme) in /app/web/modules/contrib/tinypng/src/Controller/TinyPngImageStyleDownloadController.php on line 91
Steps to reproduce
After update just run: drush updb
or drush cr
Proposed resolution
Not sure. Copying the syntax from similar errors on
WebP fallback image
π
Error after upgrading Drupal 10.2.7 to 10.3.0
Needs review
and
ImageAPI Optimize WebP
π
PHP Fatal error: Declaration of Drupal\imageapi_optimize_webp\Controller\ImageStyleDownloadController::deliver
Needs work
makes the errors go away but I don't understand the code well enough to know if this is a good fix:
diff --git a/src/Controller/TinyPngImageStyleDownloadController.php b/src/Controller/TinyPngImageStyleDownloadController.php
index 8594184..3108c4d 100644
--- a/src/Controller/TinyPngImageStyleDownloadController.php
+++ b/src/Controller/TinyPngImageStyleDownloadController.php
@@ -88,11 +88,11 @@ class TinyPngImageStyleDownloadController extends ImageStyleDownloadController {
* This is not a good solution. Replace this if
* https://www.drupal.org/project/drupal/issues/2940016 is closed.
*/
- public function deliver(Request $request, $scheme, ImageStyleInterface $image_style) {
+ public function deliver(Request $request, $scheme, ImageStyleInterface $image_style, string $required_derivative_scheme) {
// If compression is not enabled for image style use core image deliver
// method.
if (!$image_style->getThirdPartySetting('tinypng', 'tinypng_compress')) {
- return parent::deliver($request, $scheme, $image_style);
+ return parent::deliver($request, $scheme, $image_style, $required_derivative_scheme);
}
$target = $request->query->get('file');
diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php
index 75d5d2f..cc7263b 100644
--- a/src/Routing/RouteSubscriber.php
+++ b/src/Routing/RouteSubscriber.php
@@ -20,10 +20,16 @@ class RouteSubscriber extends RouteSubscriberBase {
// https://www.drupal.org/project/drupal/issues/2940016 is closed.
/** @var \Symfony\Component\Routing\Route $route */
if ($route = $collection->get('image.style_public')) {
- $route->setDefault('_controller', '\Drupal\tinypng\Controller\TinyPngImageStyleDownloadController::deliver');
+ $route->setDefault(
+ '_controller', 'Drupal\tinypng\Controller\TinyPngImageStyleDownloadController::deliver',
+ 'required_derivative_scheme', 'public'
+ );
}
if ($route = $collection->get('image.style_private')) {
- $route->setDefault('_controller', '\Drupal\tinypng\Controller\TinyPngImageStyleDownloadController::deliver');
+ $route->setDefault(
+ '_controller', 'Drupal\tinypng\Controller\TinyPngImageStyleDownloadController::deliver',
+ 'required_derivative_scheme', 'private'
+ );
}
}