/**
  * @param NodeInterface $referenceNode
  * @param string $idealNodeName
  * @param string $nodeTypeName
  * @param array $properties
  * @throws \Exception
  * @return NodeInterface
  */
 public function createChildNode(NodeInterface $referenceNode, $idealNodeName, $nodeTypeName, array $properties = [])
 {
     $this->processProperties($properties);
     $nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
     $node = $referenceNode->createNode($this->getFreeNodeName($idealNodeName, $referenceNode), $nodeType);
     $nodeTypeProperties = $nodeType->getProperties();
     foreach ($properties as $propertyName => $propertyValue) {
         if (in_array($propertyName, $this->dateProperties)) {
             try {
                 $propertyValue = trim($propertyValue);
                 if (!empty($propertyValue)) {
                     $propertyValue = new \DateTime($propertyValue);
                 }
                 if ($propertyValue === 'Invalid date') {
                     $propertyValue = null;
                 }
                 if (!$propertyValue instanceof \DateTime && $propertyName === 'publicationDate') {
                     $propertyValue = new \DateTime();
                 }
             } catch (\Exception $exception) {
                 $propertyValue = null;
             }
         }
         if (!isset($nodeTypeProperties[$propertyName])) {
             $this->logger->log(sprintf('Could not add non-existent property "%s"', $propertyName), LOG_WARNING);
             continue;
         }
         if (is_string($propertyValue)) {
             $allowedTags = in_array($propertyName, $this->editorProperties) ? $this->editorTagWhitelist : '';
             $propertyValue = strip_tags($propertyValue, $allowedTags);
         }
         $node->setProperty($propertyName, $propertyValue);
     }
     if ($node->getNodeType()->isOfType('TYPO3.Neos:Document')) {
         $node->setProperty('uriPathSegment', $node->getName());
     }
     $this->publishingService->emitNodePublished($node);
     return $node;
 }
 /**
  * Creates a new content context based on the given workspace and the NodeData object and additionally takes
  * the current site and current domain into account.
  *
  * @param Workspace $workspace Workspace for the new context
  * @param array $dimensionValues The dimension values for the new context
  * @param array $contextProperties Additional pre-defined context properties
  * @return Context
  */
 protected function createContext(Workspace $workspace, array $dimensionValues, array $contextProperties = array())
 {
     if ($this->currentDomain === false) {
         $this->currentDomain = $this->domainRepository->findOneByActiveRequest();
     }
     if ($this->currentDomain !== null) {
         $contextProperties['currentSite'] = $this->currentDomain->getSite();
         $contextProperties['currentDomain'] = $this->currentDomain;
     } else {
         if ($this->currentSite === false) {
             $this->currentSite = $this->siteRepository->findFirstOnline();
         }
         $contextProperties['currentSite'] = $this->currentSite;
     }
     return parent::createContext($workspace, $dimensionValues, $contextProperties);
 }