Ejemplo n.º 1
0
 /**
  * Testcase for http://forge.typo3.org/issues/39445
  *
  * @test
  */
 public function ifTargetObjectTypeIsPassedRecursivelyDoNotConvertIt()
 {
     $entity = new Fixtures\TestEntity();
     $entity->setName('Egon Olsen');
     $result = $this->propertyMapper->convert(array($entity), 'array<TYPO3\\FLOW3\\Tests\\Functional\\Property\\Fixtures\\TestEntity>');
     $this->assertSame(array($entity), $result);
 }
Ejemplo n.º 2
0
 /**
  * @param array<\TYPO3\TYPO3CR\Domain\Model\NodeInterface> $nodes
  * @param string $action
  * @return void
  */
 public function publishOrDiscardNodesAction(array $nodes, $action)
 {
     $propertyMappingConfiguration = $this->propertyMappingConfigurationBuilder->build();
     $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\TYPO3\\Routing\\NodeObjectConverter', \TYPO3\TYPO3\Routing\NodeObjectConverter::REMOVED_CONTENT_SHOWN, TRUE);
     foreach ($nodes as $key => $node) {
         $nodes[$key] = $this->propertyMapper->convert($node, 'TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface', $propertyMappingConfiguration);
     }
     switch ($action) {
         case 'publish':
             foreach ($nodes as $node) {
                 $this->workspacesService->publishNode($node);
             }
             $message = 'Selected changes have been published';
             break;
         case 'discard':
             foreach ($nodes as $node) {
                 $this->nodeRepository->remove($node);
             }
             $message = 'Selected changes have been discarded';
             break;
         default:
             throw new \RuntimeException('Invalid action "' . $action . '" given.', 1346167441);
     }
     $this->flashMessageContainer->addMessage(new \TYPO3\FLOW3\Error\Message($message));
     $this->redirect('index');
 }
Ejemplo n.º 3
0
 /**
  * Sets the value of this argument.
  *
  * @param mixed $rawValue The value of this argument
  * @return \TYPO3\FLOW3\Mvc\Controller\Argument $this
  */
 public function setValue($rawValue)
 {
     if ($rawValue === NULL) {
         $this->value = NULL;
         return $this;
     }
     if (is_object($rawValue) && $rawValue instanceof $this->dataType) {
         $this->value = $rawValue;
         return $this;
     }
     $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration);
     $this->validationResults = $this->propertyMapper->getMessages();
     if ($this->validator !== NULL) {
         $validationMessages = $this->validator->validate($this->value);
         $this->validationResults->merge($validationMessages);
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Converts the specified node path into a Node.
  *
  * The node path must be an absolute context node path and can be specified as a string or as an array item with the
  * key "__contextNodePath". The latter case is for updating existing nodes.
  *
  * This conversion method does not support / allow creation of new nodes because new nodes should be created through
  * the createNode() method of an existing reference node.
  *
  * Also note that the context's "current node" is not affected by this object converter, you will need to set it to
  * whatever node your "current" node is, if any.
  *
  * All elements in the source array which start with two underscores (like __contextNodePath) are specially treated
  * by this converter.
  *
  * All elements in the source array which start with a *single underscore (like _hidden) are *directly* set on the Node
  * object.
  *
  * All other elements, not being prefixed with underscore, are properties of the node.
  *
  * @param string|array $source Either a string or array containing the absolute context node path which identifies the node. For example "/sites/mysitecom/homepage/about@user-admin"
  * @param string $targetType not used
  * @param array $subProperties not used
  * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration not used
  * @return mixed An object or \TYPO3\FLOW3\Error\Error if the input format is not supported or could not be converted for other reasons
  * @throws \Exception
  */
 public function convertFrom($source, $targetType, array $subProperties = array(), \TYPO3\FLOW3\Property\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);
     }
     preg_match(NodeInterface::MATCH_PATTERN_CONTEXTPATH, $source['__contextNodePath'], $matches);
     if (!isset($matches['NodePath'])) {
         return new Error('Could not convert array to Node object because the node path was invalid.', 1285162903);
     }
     $nodePath = $matches['NodePath'];
     if ($this->nodeRepository->getContext() === NULL) {
         $workspaceName = isset($matches['WorkspaceName']) ? $matches['WorkspaceName'] : 'live';
         $contentContext = new ContentContext($workspaceName);
         $this->nodeRepository->setContext($contentContext);
     } else {
         $contentContext = $this->nodeRepository->getContext();
         $workspaceName = $contentContext->getWorkspace()->getName();
     }
     if ($workspaceName !== 'live') {
         $contentContext->setInvisibleContentShown(TRUE);
         if ($configuration->getConfigurationValue('TYPO3\\TYPO3\\Routing\\NodeObjectConverter', self::REMOVED_CONTENT_SHOWN) === TRUE) {
             $contentContext->setRemovedContentShown(TRUE);
         }
     }
     $workspace = $contentContext->getWorkspace(FALSE);
     if (!$workspace) {
         return new Error(sprintf('Could not convert %s to Node object because the workspace "%s" as specified in the context node path does not exist.', $source['__contextNodePath'], $workspaceName), 1285162905);
     }
     $currentAccessModeFromContext = $contentContext->isInaccessibleContentShown();
     $contentContext->setInaccessibleContentShown(TRUE);
     $node = $contentContext->getNode($nodePath);
     $contentContext->setInaccessibleContentShown($currentAccessModeFromContext);
     if (!$node) {
         return new Error(sprintf('Could not convert array to Node object because the node "%s" does not exist.', $nodePath), 1285162908);
     }
     $contentTypeProperties = $node->getContentType()->getProperties();
     foreach ($source as $nodePropertyKey => $nodePropertyValue) {
         if (substr($nodePropertyKey, 0, 2) === '__') {
             continue;
         }
         if ($nodePropertyKey[0] === '_') {
             $propertyName = substr($nodePropertyKey, 1);
             // TODO: Hack: we need to create DateTime objects for some properties of Node
             if (($propertyName === 'hiddenBeforeDateTime' || $propertyName === 'hiddenAfterDateTime') && is_string($nodePropertyValue)) {
                 if ($nodePropertyValue !== '') {
                     $nodePropertyValue = \DateTime::createFromFormat('!Y-m-d', $nodePropertyValue);
                 } else {
                     $nodePropertyValue = NULL;
                 }
             }
             \TYPO3\FLOW3\Reflection\ObjectAccess::setProperty($node, $propertyName, $nodePropertyValue);
         } else {
             if (!isset($contentTypeProperties[$nodePropertyKey])) {
                 throw new \Exception('TODO: content type XY does not have a property YY according to the schema');
             }
             if (isset($contentTypeProperties[$nodePropertyKey]['type'])) {
                 $targetType = $contentTypeProperties[$nodePropertyKey]['type'];
                 if ($this->objectManager->isRegistered($targetType)) {
                     $nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, TRUE), $targetType);
                 }
             }
             $node->setProperty($nodePropertyKey, $nodePropertyValue);
         }
     }
     return $node;
 }