diff --git a/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php b/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php index cb1583005a..9d9b821cff 100644 --- a/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php +++ b/Neos.FluidAdaptor/Classes/Core/ViewHelper/TemplateVariableContainer.php @@ -11,6 +11,8 @@ * source code. */ +use Neos\Utility\Exception\PropertyNotAccessibleException; +use Neos\Utility\ObjectAccess; use Neos\FluidAdaptor\Core\Parser\SyntaxTree\TemplateObjectAccessInterface; use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider; use TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface; @@ -22,25 +24,27 @@ */ class TemplateVariableContainer extends StandardVariableProvider implements VariableProviderInterface { + const ACCESSOR_OBJECT_ACCESS = 'object_access'; + /** * Get a variable by dotted path expression, retrieving the * variable from nested arrays/objects one segment at a time. + * If the second argument is provided, it must be an array of + * accessor names which can be used to extract each value in + * the dotted path. * * @param string $path + * @param array $accessors * @return mixed */ - public function getByPath($path) + public function getByPath($path, array $accessors = []) { - $subject = parent::getByPath($path); + $subject = parent::getByPath($path, $accessors); if ($subject === null) { $subject = $this->getBooleanValue($path); } - if ($subject instanceof TemplateObjectAccessInterface) { - return $subject->objectAccess(); - } - return $subject; } @@ -61,6 +65,42 @@ protected function resolveSubVariableReferences(string $propertyPath): string return $propertyPath; } + /** + * @param mixed $subject + * @param string $propertyName + * @return NULL|string + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + protected function detectAccessor($subject, $propertyName) + { + return TemplateVariableContainer::ACCESSOR_OBJECT_ACCESS; + } + + /** + * @param mixed $subject + * @param string $propertyName + * @param string $accessor + * @return mixed|null + */ + protected function extractWithAccessor($subject, $propertyName, $accessor) + { + if (TemplateVariableContainer::ACCESSOR_OBJECT_ACCESS === $accessor) { + try { + $subject = ObjectAccess::getProperty($subject, $propertyName); + } catch (PropertyNotAccessibleException $e) { + $subject = null; + } + } else { + $subject = parent::extractWithAccessor($subject, $propertyName, $accessor); + } + + if ($subject instanceof TemplateObjectAccessInterface) { + return $subject->objectAccess(); + } + + return $subject; + } + /** * Tries to interpret the given path as boolean value, either returns the boolean value or null. *