public function reverseTransform($uuid) { if (!$uuid) { return; } if (!UUIDHelper::isUuid($uuid)) { throw new TransformationFailedException(sprintf('Given UUID is not a UUID, given: "%s"', $uuid)); } $document = $this->documentManager->find($uuid); if (null === $document) { throw new TransformationFailedException(sprintf('Could not find document with UUID "%s"', $uuid)); } return $document; }
public function execute(InputInterface $input, OutputInterface $output) { $session = $this->get('phpcr.session'); $pathHelper = $this->get('helper.path'); $path = $session->getAbsPath($input->getArgument('path')); $value = $input->getArgument('value'); $type = $input->getOption('type'); $nodePath = $pathHelper->getParentPath($path); $propName = $pathHelper->getNodeName($path); $nodes = $session->findNodes($nodePath); foreach ($nodes as $node) { $intType = null; if ($type) { $intType = PropertyType::valueFromName($type); if ($intType === PropertyType::REFERENCE || $intType === PropertyType::WEAKREFERENCE) { // convert path to UUID if (false === UUIDHelper::isUuid($value)) { $path = $value; try { $targetNode = $session->getNode($path); $value = $targetNode->getIdentifier(); } catch (PathNotFoundException $e) { } if (null === $value) { throw new \InvalidArgumentException(sprintf('Node at path "%s" specified for reference is not referenceable', $path)); } } } } else { try { $property = $node->getProperty($propName); $intType = $property->getType(); } catch (PathNotFoundException $e) { // property doesn't exist and no type specified, default to string $intType = PropertyType::STRING; } } $node->setProperty($propName, $value, $intType); } }
public function testGetReferencedUuids() { $pageNode = $this->session->getNode('/cmf/sulu_io/contents/hotels'); $pageStructure = $this->contentMapper->loadByNode($pageNode, 'en', 'sulu_io', true, false, false); $property = $pageStructure->getProperty('hotels'); $uuids = $this->contentType->getReferencedUuids($property); $this->assertCount(2, $uuids); foreach ($uuids as $uuid) { $this->assertTrue(UUIDHelper::isUuid($uuid)); } }