protected function setNodeProperties($nodeLike, NodeType $nodeType, array $properties, TYPO3CRContext $context, PropertyMappingConfigurationInterface $configuration = null)
{
$nodeTypeProperties = $nodeType->getProperties();
unset($properties['_lastPublicationDateTime']);
foreach ($properties as $nodePropertyName => $nodePropertyValue) {
if (substr($nodePropertyName, 0, 2) === '__') {
continue;
}
$nodePropertyType = isset($nodeTypeProperties[$nodePropertyName]['type']) ? $nodeTypeProperties[$nodePropertyName]['type'] : null;
switch ($nodePropertyType) {
case 'reference':
$nodePropertyValue = $context->getNodeByIdentifier($nodePropertyValue);
break;
case 'references':
$nodeIdentifiers = json_decode($nodePropertyValue);
$nodePropertyValue = array();
if (is_array($nodeIdentifiers)) {
foreach ($nodeIdentifiers as $nodeIdentifier) {
$referencedNode = $context->getNodeByIdentifier($nodeIdentifier);
if ($referencedNode !== null) {
$nodePropertyValue[] = $referencedNode;
}
}
} elseif ($nodeIdentifiers !== null) {
throw new TypeConverterException(sprintf('node type "%s" expects an array of identifiers for its property "%s"', $nodeType->getName(), $nodePropertyName), 1383587419);
}
break;
case 'DateTime':
if ($nodePropertyValue !== '' && ($nodePropertyValue = \DateTime::createFromFormat(\DateTime::W3C, $nodePropertyValue)) !== false) {
$nodePropertyValue->setTimezone(new \DateTimeZone(date_default_timezone_get()));
} else {
$nodePropertyValue = null;
}
break;
case 'integer':
$nodePropertyValue = intval($nodePropertyValue);
break;
case 'boolean':
if (is_string($nodePropertyValue)) {
$nodePropertyValue = $nodePropertyValue === 'true' ? true : false;
}
break;
case 'array':
$nodePropertyValue = json_decode($nodePropertyValue, true);
break;
}
if (substr($nodePropertyName, 0, 1) === '_') {
$nodePropertyName = substr($nodePropertyName, 1);
ObjectAccess::setProperty($nodeLike, $nodePropertyName, $nodePropertyValue);
continue;
}
if (!isset($nodeTypeProperties[$nodePropertyName])) {
if ($configuration !== null && $configuration->shouldSkipUnknownProperties()) {
continue;
} else {
throw new TypeConverterException(sprintf('Node type "%s" does not have a property "%s" according to the schema', $nodeType->getName(), $nodePropertyName), 1359552744);
}
}
$innerType = $nodePropertyType;
if ($nodePropertyType !== null) {
try {
$parsedType = TypeHandling::parseType($nodePropertyType);
$innerType = $parsedType['elementType'] ?: $parsedType['type'];
} catch (InvalidTypeException $exception) {
}
}
if (is_string($nodePropertyValue) && $this->objectManager->isRegistered($innerType) && $nodePropertyValue !== '') {
$nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, true), $nodePropertyType, $configuration);
}
$nodeLike->setProperty($nodePropertyName, $nodePropertyValue);
}
}