Feature #101125
openAbility to convert Domain Models to Array
0%
Description
In the same context with this https://forge.typo3.org/issues/101124, it would be very practical if there was a function in the AbstractEntity , which converts the Model to array.
Technology is moving fast, and headless and communication between systems are made mostly with json strings. Currently, one has to create a method in the domain model which return the values as arrays, but this also could be PITA if an extension has 10+ models and relations. Specially now that with TYPO3 12, we have Webhooks and Reactions , which makes the communication between systems very easy.
Solution
Create a method in AbstractEntity which processes everything (FileReferences, Relations) and return everything as an array
Updated by Benni Mack over 1 year ago
- Related to Feature #101124: Make Templates optional in Extbase added
Updated by Stefan Froemken over 1 year ago
Hello Karavas,
You can use \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGetableProperties($object); to do so in your controller.
I know, that this method needs a further method to do its job recursive. Maybe I can create a patch for that.
Would that be an option for you?
Stefan
Updated by Aristeidis Karavas about 1 year ago
Hallo Stefan,
calling another class to modify the current called Model, i think it is too much. The same could be achieved by not calling the model at all and just make a QueryBuilder request with all the joins. A more suitable approach would be a function inside the model which returns everything as array, so the developer could just do something like that: $object = $this->someRepository->findByUid()->toArray
Not saying that the current implementation it is not a solution, but the other one would be more practical and understandable, specially when it comes to documentation
If it is too much, or not possible with the current state of TYPO3, sure, creating a patch for the ObjectAccess would be ok
Aris