From eab588dc6f98a0c585a3b93f17643904638fb3fa Mon Sep 17 00:00:00 2001 From: Karsten Dambekalns Date: Sat, 25 May 2024 13:47:39 +0200 Subject: [PATCH] BUGFIX: Do proper resolving of FusionPathProxy Using `{image.title}` in Fluid when the image is a `FusionPathProxy` does not work. The result is simply `null` instead of the image title. This change fixes that by moving more code down into our own custom `TemplateVariableContainer` from the `StandardVariableProvider`. Fixes neos/flow-development-collection#3357 --- .../ViewHelper/TemplateVariableContainer.php | 59 ++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php b/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php index cb1583005a..ed8daa2103 100644 --- a/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php +++ b/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php @@ -1,4 +1,5 @@ variables; + $subVariableReferences = explode('.', $this->resolveSubVariableReferences($path)); + foreach ($subVariableReferences as $pathSegment) { + // begin TemplateObjectAccessInterface handling + if ($subject instanceof TemplateObjectAccessInterface) { + $subject = $subject->objectAccess(); + } + // end TemplateObjectAccessInterface handling + if ((is_array($subject) && array_key_exists($pathSegment, $subject)) + || ($subject instanceof \ArrayAccess && $subject->offsetExists($pathSegment)) + ) { + $subject = $subject[$pathSegment]; + continue; + } + if (is_object($subject)) { + $upperCasePropertyName = ucfirst($pathSegment); + $getMethod = 'get' . $upperCasePropertyName; + if (method_exists($subject, $getMethod)) { + $subject = $subject->$getMethod(); + continue; + } + $isMethod = 'is' . $upperCasePropertyName; + if (method_exists($subject, $isMethod)) { + $subject = $subject->$isMethod(); + continue; + } + $hasMethod = 'has' . $upperCasePropertyName; + if (method_exists($subject, $hasMethod)) { + $subject = $subject->$hasMethod(); + continue; + } + if (property_exists($subject, $pathSegment)) { + $subject = $subject->$pathSegment; + continue; + } + } + // begin TemplateObjectAccessInterface handling + $subject = null; + break; + // end TemplateObjectAccessInterface handling + } + // end copy of parent method if ($subject === null) { $subject = $this->getBooleanValue($path); } + // we might still have a TemplateObjectAccessInterface instance if ($subject instanceof TemplateObjectAccessInterface) { - return $subject->objectAccess(); + $subject = $subject->objectAccess(); } return $subject; @@ -63,11 +109,8 @@ protected function resolveSubVariableReferences(string $propertyPath): string /** * Tries to interpret the given path as boolean value, either returns the boolean value or null. - * - * @param $path - * @return boolean|null */ - protected function getBooleanValue($path) + protected function getBooleanValue(string $path): ?bool { $normalizedPath = strtolower($path);