Bug #34404
JsonView transformObject does not respect _descendAll configuration
Status: | New | Start date: | 2012-02-29 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | - | % Done: | 0% |
|
Category: | - | |||
Target version: | - | |||
PHP Version: | Complexity: | easy | ||
Has patch: | No | Affected Flow version: | Git master |
Description
When configuring a jsonView for a domain object, the '_descendAll' configuration is currently not taken into account, leading to the need to configure all properties for traversal.
The part of TYPO3\FLOW3\MVC\View\JsonView::transformObject line 199+
if (!is_array($propertyValue) && !is_object($propertyValue)) { $propertiesToRender[$propertyName] = $propertyValue; } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) { $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]); }
should be
if (!is_array($propertyValue) && !is_object($propertyValue)) { $propertiesToRender[$propertyName] = $propertyValue; } elseif (isset($configuration['_descendAll'])) { $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descendAll']); } elseif (isset($configuration['_descend']) && array_key_exists($propertyName, $configuration['_descend'])) { $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration['_descend'][$propertyName]); }
A further nice-to-have feature would be a real _descendAll configuration that just carelessly descends all objects, though it probably should still deal with recursion of domain objects or stop at a specific recursion depth.
Something like an int configuration _recursionDepth would work:
} elseif (isset($configuration['_recursionDepth']) && $configuration['_recursionDepth'] > 0) { $configuration['_recursionDepth']--; $propertiesToRender[$propertyName] = $this->transformValue($propertyValue, $configuration);
On a side note: The current implementation for configuration settings behaves differently for arrays / ArrayAccess objects and other objects.
While for arrays, _descendAll overrules _only and _exclude settings, for an object _only and _exclude overrule _descend (and with the patch above also _descendAll).