public function convertFrom($source, $targetType = null, array $subProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
{
if (is_string($source)) {
$source = array('__contextNodePath' => $source);
}
if (!is_array($source) || !isset($source['__contextNodePath'])) {
return new Error('Could not convert ' . gettype($source) . ' to Node object, a valid absolute context node path as a string or array is expected.', 1302879936);
}
try {
$nodePathAndContext = NodePaths::explodeContextPath($source['__contextNodePath']);
$nodePath = $nodePathAndContext['nodePath'];
$workspaceName = $nodePathAndContext['workspaceName'];
$dimensions = $nodePathAndContext['dimensions'];
} catch (\InvalidArgumentException $exception) {
return new Error('Could not convert array to Node object because the node path was invalid.', 1285162903);
}
$context = $this->contextFactory->create($this->prepareContextProperties($workspaceName, $configuration, $dimensions));
$workspace = $context->getWorkspace(false);
if (!$workspace) {
return new Error(sprintf('Could not convert the given source to Node object because the workspace "%s" as specified in the context node path does not exist.', $workspaceName), 1383577859);
}
$node = $context->getNode($nodePath);
if (!$node) {
return new Error(sprintf('Could not convert array to Node object because the node "%s" does not exist.', $nodePath), 1370502328);
}
if (isset($source['_nodeType']) && $source['_nodeType'] !== $node->getNodeType()->getName()) {
if ($context->getWorkspace()->getName() === 'live') {
throw new NodeException('Could not convert the node type in live workspace', 1429989736);
}
$oldNodeType = $node->getNodeType();
$targetNodeType = $this->nodeTypeManager->getNodeType($source['_nodeType']);
$node->setNodeType($targetNodeType);
$this->nodeService->setDefaultValues($node);
$this->nodeService->cleanUpAutoCreatedChildNodes($node, $oldNodeType);
$this->nodeService->createChildNodes($node);
}
unset($source['_nodeType']);
$this->setNodeProperties($node, $node->getNodeType(), $source, $context, $configuration);
return $node;
}