I have an Entity like that:
class Company extends AbstractEntity
{
/**
* @var string
*/
protected $longName = \'\';
//much more properties
//all
The reason for such a thing is a kind of a hack/workaround, to use the workspaces functionality from the frontend. That bypasses the database abstraction layer, which is very nice to have, just to trigger some hooks. I hope that this wont be needed in future releases but for now, I could solve it with this solution:
public function map(AbstractEntity $entity):array
{
$result = [];
$class = get_class($entity);
/** @var ClassReflection $reflection */
$reflection = GeneralUtility::makeInstance(ClassReflection::class, $class);
/** @var DataMapper $mapper */
$mapper = GeneralUtility::makeInstance(DataMapper::class);
$dataMap = $mapper->getDataMap($class);
foreach ($entity->_getProperties() as $property => $value) {
$colMap = $dataMap->getColumnMap($property);
$reflProp = $reflection->getProperty($property);
if (!is_null($colMap) and $reflProp->isTaggedWith('maptce')) {
$result[$colMap->getColumnName()] = $mapper->getPlainValue($value, $colMap);
}
}
return $result;
}
That basically does something like \TYPO3\CMS\Extbase\Persistence\Generic\Backend::persistObject()
and most of the code is taken from there as well. But the general Data mapping especially for nested Entities and so on is would have been too complex for now, so I decided to just test if a property has an @maptce
annotation to simplify the process.
It is no Problem to skip some properties since the TCE process_datamap()
method will care about that.