From f8ff0fe8c4a93d7c9653e8054eaf739c22da8f64 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 15 Mar 2026 13:57:19 +0300 Subject: [PATCH] [fix] Fix runtime filter URL generation and revert relativePath in Twig macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CacheManager::generateUrl(): unwrap processors from config to avoid double-nesting (processors[processors][fill] → processors[fill]), and sign hash with the same unwrapped data that the controller receives - CacheManager::extractDensity(): look inside processors key for density - RuntimeAction: wrap query processors back into ['processors' => ...] before passing to FilterService, so array_replace_recursive correctly merges runtime processors with filter config - Twig macros: revert to src.uri|default(src) — relativePath is removed from file-bundle, and uri works correctly for filesystem storage Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Controller/RuntimeAction.php | 2 +- src/Imagine/Cache/CacheManager.php | 13 +++++++++---- src/Resources/views/macro/image.html.twig | 16 ++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Controller/RuntimeAction.php b/src/Controller/RuntimeAction.php index cd18c9d..0082661 100644 --- a/src/Controller/RuntimeAction.php +++ b/src/Controller/RuntimeAction.php @@ -63,7 +63,7 @@ public function __invoke(Request $request, string $hash, string $path, string $f throw new BadRequestHttpException(\sprintf('Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', $path, $filter, \json_encode($config))); } - return $this->processAndRespond($this->filterService, $path, $filter, $config, resolver: $resolver); + return $this->processAndRespond($this->filterService, $path, $filter, ['processors' => $config], resolver: $resolver); } /** diff --git a/src/Imagine/Cache/CacheManager.php b/src/Imagine/Cache/CacheManager.php index 1690c9a..27da5a9 100644 --- a/src/Imagine/Cache/CacheManager.php +++ b/src/Imagine/Cache/CacheManager.php @@ -94,8 +94,10 @@ public function generateUrl(string $path, string $filter, array $config, ?string $params['resolver'] = $resolver; } - $params['processors'] = $config; - $params['hash'] = $this->signer->sign($path, $this->getFilterSecret($filter), $config); + /** @var array $processors */ + $processors = $config['processors'] ?? $config; + $params['processors'] = $processors; + $params['hash'] = $this->signer->sign($path, $this->getFilterSecret($filter), $processors); return $this->router->generate('_chamber_orchestra_image', $params, $referenceType); } @@ -155,8 +157,11 @@ public function remove(string $path): void */ private function extractDensity(array $config): int { - foreach ($config as $key => $value) { - if ('output' !== $key && \is_array($value) && \is_numeric($value['density'] ?? null)) { + /** @var array $processors */ + $processors = $config['processors'] ?? $config; + + foreach ($processors as $value) { + if (\is_array($value) && \is_numeric($value['density'] ?? null)) { return (int) $value['density']; } } diff --git a/src/Resources/views/macro/image.html.twig b/src/Resources/views/macro/image.html.twig index bf6687a..0e605da 100644 --- a/src/Resources/views/macro/image.html.twig +++ b/src/Resources/views/macro/image.html.twig @@ -13,8 +13,8 @@ {%- endmacro -%} {%- macro fit(src, width, height, attr, picture_attr = {}) -%} - {# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #} - {%- set src = src.relativePath|default(src.uri|default(src)) -%} + {# add support of ChamberOrchestra\FileBundle\Model\File #} + {%- set src = src.uri|default(src) -%} {%- set attr = attr|default({})|merge({width: attr.width|default(width), height: attr.height|default(height), style: 'height: auto', loading: 'lazy', decoding: 'async'}) -%} @@ -61,8 +61,8 @@ {%- macro css_fit(src, width, height, use2x = true) -%} - {# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #} - {%- set src = src.relativePath|default(src.uri|default(src)) -%} + {# add support of ChamberOrchestra\FileBundle\Model\File #} + {%- set src = src.uri|default(src) -%} {%- set url = (src|default('')|fit(width, height)) -%} {%- set webp = (src|default('')|fit(width, height, {output: {format: 'webp'}})) -%} {%- set avif = (src|default('')|fit(width, height, {output: {format: 'avif'}})) -%} @@ -104,8 +104,8 @@ {%- macro css_fill(src, width, height, use2x = true) -%} - {# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #} - {%- set src = src.relativePath|default(src.uri|default(src)) -%} + {# add support of ChamberOrchestra\FileBundle\Model\File #} + {%- set src = src.uri|default(src) -%} {%- set url = (src|default('')|fill(width, height)) -%} {%- set webp = (src|default('')|fill(width, height, {output: {format: 'webp'}})) -%}