/** * Set the node title for the newly created Document node * * @param NodeInterface $node The newly created node * @param array $data incoming data from the creationDialog * @return void */ public function handle(NodeInterface $node, array $data) { if (isset($data['title']) && $node->getNodeType()->isOfType('TYPO3.Neos:Document')) { $node->setProperty('title', $data['title']); $node->setProperty('uriPathSegment', NodeUtility::renderValidNodeName($data['title'])); } }
/** * Helper method for creating a new node. * * @param NodeInterface $referenceNode * @param array $nodeData * @param string $position * @return NodeInterface * @throws \InvalidArgumentException */ public function create(NodeInterface $referenceNode, array $nodeData, $position) { if (!in_array($position, array('before', 'into', 'after'), true)) { throw new \InvalidArgumentException('The position should be one of the following: "before", "into", "after".', 1347133640); } $nodeType = $this->nodeTypeManager->getNodeType($nodeData['nodeType']); if ($nodeType->isOfType('TYPO3.Neos:Document') && !isset($nodeData['properties']['uriPathSegment']) && isset($nodeData['properties']['title'])) { $nodeData['properties']['uriPathSegment'] = Utility::renderValidNodeName($nodeData['properties']['title']); } $proposedNodeName = isset($nodeData['nodeName']) ? $nodeData['nodeName'] : null; $nodeData['nodeName'] = $this->nodeService->generateUniqueNodeName($this->getDesignatedParentNode($referenceNode, $position)->getPath(), $proposedNodeName); if ($position === 'into') { $newNode = $referenceNode->createNode($nodeData['nodeName'], $nodeType); } else { $parentNode = $referenceNode->getParent(); $newNode = $parentNode->createNode($nodeData['nodeName'], $nodeType); if ($position === 'before') { $newNode->moveBefore($referenceNode); } else { $newNode->moveAfter($referenceNode); } } if (isset($nodeData['properties']) && is_array($nodeData['properties'])) { foreach ($nodeData['properties'] as $propertyName => $propertyValue) { $newNode->setProperty($propertyName, $propertyValue); } } return $newNode; }
/** * @param NodeInterface $parentNode * @param NodeType $nodeType * @return NodeInterface|void */ public function create(NodeInterface $parentNode, NodeType $nodeType) { $title = Company::name(); $name = Utility::renderValidNodeName($title); $childrenNode = $parentNode->createNode($name, $nodeType); $childrenNode->setProperty('title', $title); return $childrenNode; }
/** * @param string $sitePackage * @param string $siteName * @param string $baseDomain * @return Site */ public function importSiteFromTemplate($sitePackage, $siteName, $baseDomain = '') { if (empty($baseDomain)) { $request = Request::createFromEnvironment(); $baseDomain = $request->getBaseUri()->getHost(); } $siteTemplate = new StandaloneView(); $siteTemplate->setTemplatePathAndFilename(FLOW_PATH_PACKAGES . 'Sites/' . $sitePackage . '/Resources/Private/Templates/Content/Sites.xml'); $siteTemplate->assignMultiple(['siteName' => $siteName, 'siteNodeName' => \TYPO3\TYPO3CR\Utility::renderValidNodeName($siteName), 'packageKey' => $sitePackage]); $generatedSiteImportXmlContent = $siteTemplate->render(); $dataTemporaryPath = $this->environment->getPathToTemporaryDirectory(); $temporarySiteXml = $dataTemporaryPath . uniqid($siteName) . '.xml'; file_put_contents($temporarySiteXml, $generatedSiteImportXmlContent); $site = $this->siteImportService->importFromFile($temporarySiteXml); $domain = new Domain(); $domain->setActive(true); $domain->setSite($site); $domain->setHostPattern(\TYPO3\TYPO3CR\Utility::renderValidNodeName($siteName) . '.' . $baseDomain); $this->domainRepository->add($domain); return $site; }
/** * Parses the given XML element and adds its content to the internal content tree * * @param \XMLReader $xmlReader The XML Reader with the element to be parsed as its root * @return void * @throws ImportException */ protected function parseElement(\XMLReader $xmlReader) { $elementName = $xmlReader->name; switch ($elementName) { case 'node': // update current node identifier $this->nodeIdentifierStack[] = $xmlReader->getAttribute('identifier'); // update current path $nodeName = $xmlReader->getAttribute('nodeName'); if ($nodeName !== '/') { $this->nodeNameStack[] = Utility::renderValidNodeName($nodeName); } break; case 'variant': $path = $this->getCurrentPath(); $parentPath = $this->getParentPath($path); $now = new Now(); $currentNodeIdentifier = $this->nodeIdentifierStack[count($this->nodeIdentifierStack) - 1]; $this->nodeDataStack[] = array('Persistence_Object_Identifier' => Algorithms::generateUUID(), 'identifier' => $currentNodeIdentifier, 'nodeType' => $xmlReader->getAttribute('nodeType'), 'workspace' => $xmlReader->getAttribute('workspace'), 'sortingIndex' => $xmlReader->getAttribute('sortingIndex'), 'version' => $xmlReader->getAttribute('version'), 'removed' => (bool) $xmlReader->getAttribute('removed'), 'hidden' => (bool) $xmlReader->getAttribute('hidden'), 'hiddenInIndex' => (bool) $xmlReader->getAttribute('hiddenInIndex'), 'path' => $path, 'pathHash' => md5($path), 'parentPath' => $parentPath, 'parentPathHash' => md5($parentPath), 'properties' => array(), 'accessRoles' => array(), 'creationDateTime' => $now, 'lastModificationDateTime' => $now, 'dimensionValues' => array()); break; case 'dimensions': $this->nodeDataStack[count($this->nodeDataStack) - 1]['dimensionValues'] = $this->parseDimensionsElement($xmlReader); break; case 'properties': $this->nodeDataStack[count($this->nodeDataStack) - 1]['properties'] = $this->parsePropertiesElement($xmlReader); break; case 'accessRoles': $this->nodeDataStack[count($this->nodeDataStack) - 1]['accessRoles'] = $this->parseArrayElements($xmlReader, 'accessRoles'); break; case 'hiddenBeforeDateTime': case 'hiddenAfterDateTime': case 'creationDateTime': case 'lastModificationDateTime': case 'lastPublicationDateTime': $this->nodeDataStack[count($this->nodeDataStack) - 1][$elementName] = $this->propertyMapper->convert($xmlReader->readString(), 'DateTime', $this->propertyMappingConfiguration); break; default: throw new ImportException(sprintf('Unexpected element <%s> ', $elementName), 1423578065); break; } }
/** * Creates a new node beneath $parent * * @param NodeInterface $parent * @return NodeInterface */ protected function createNode(NodeInterface $parent) { $nodeType = $this->getNodeType(); $initialProperties = $this->getInitialProperties(); $name = $this->getName() ?: $this->nodeService->generateUniqueNodeName($parent->getPath()); // // If we're about to create a document, check for the presence of the uriPathSegment property first // and create it, if it's missing // if ($nodeType->isOfType('TYPO3.Neos:Document') && !isset($initialProperties['uriPathSegment'])) { if (!isset($initialProperties['title'])) { throw new \IllegalArgumentException('You must either provide a title or a uriPathSegment in order to create a document.', 1452103891); } $initialProperties['uriPathSegment'] = NodeUtility::renderValidNodeName($initialProperties['title']); } $node = $parent->createNode($name, $nodeType); foreach ($initialProperties as $key => $value) { $node->setProperty($key, $value); } return $node; }
/** * Create a workspace * * @Flow\Validate(argumentName="title", type="\TYPO3\Flow\Validation\Validator\NotEmptyValidator") * @param string $title Human friendly title of the workspace, for example "Christmas Campaign" * @param Workspace $baseWorkspace Workspace the new workspace should be based on * @param string $visibility Visibility of the new workspace, must be either "internal" or "shared" * @param string $description A description explaining the purpose of the new workspace * @return void */ public function createAction($title, Workspace $baseWorkspace, $visibility, $description = '') { $workspace = $this->workspaceRepository->findOneByTitle($title); if ($workspace instanceof Workspace) { $this->addFlashMessage($this->translator->translateById('workspaces.workspaceWithThisTitleAlreadyExists', [], null, null, 'Modules', 'TYPO3.Neos'), '', Message::SEVERITY_WARNING); $this->redirect('new'); } $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5); while ($this->workspaceRepository->findOneByName($workspaceName) instanceof Workspace) { $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5); } if ($visibility === 'private') { $owner = $this->userService->getCurrentUser(); } else { $owner = null; } $workspace = new Workspace($workspaceName, $baseWorkspace, $owner); $workspace->setTitle($title); $workspace->setDescription($description); $this->workspaceRepository->add($workspace); $this->redirect('index'); }
/** * Traverses through the tree starting at the given root node and sets the uriPathSegment property derived from * the node label. * * @param NodeInterface $node The node where the traversal starts * @param boolean $dryRun * @return void */ protected function generateUriPathSegmentsForNode(NodeInterface $node, $dryRun) { if ((string) $node->getProperty('uriPathSegment') === '') { $name = $node->getLabel() ?: $node->getName(); $uriPathSegment = Utility::renderValidNodeName($name); if ($dryRun === FALSE) { $node->setProperty('uriPathSegment', $uriPathSegment); $this->output->outputLine('Added missing URI path segment for "%s" (%s) => %s', array($node->getPath(), $name, $uriPathSegment)); } else { $this->output->outputLine('Found missing URI path segment for "%s" (%s) => %s', array($node->getPath(), $name, $uriPathSegment)); } } foreach ($node->getChildNodes('TYPO3.Neos:Document') as $childNode) { $this->generateUriPathSegmentsForNode($childNode, $dryRun); } }
/** * Checks if the given $nodeType is allowed as a childNode of the given $childNodeName * (which must be auto-created in $this NodeType). * * Only allowed to be called if $childNodeName is auto-created. * * @param string $childNodeName The name of a configured childNode of this NodeType * @param NodeType $nodeType The NodeType to check constraints for. * @return boolean TRUE if the $nodeType is allowed as grandchild node, FALSE otherwise. * @throws \InvalidArgumentException If the given $childNodeName is not configured to be auto-created in $this. */ public function allowsGrandchildNodeType($childNodeName, NodeType $nodeType) { $autoCreatedChildNodes = $this->getAutoCreatedChildNodes(); if (!isset($autoCreatedChildNodes[$childNodeName])) { throw new \InvalidArgumentException('The method "allowsGrandchildNodeType" can only be used on auto-created childNodes, given $childNodeName "' . $childNodeName . '" is not auto-created.', 1403858395); } $constraints = $autoCreatedChildNodes[$childNodeName]->getConfiguration('constraints.nodeTypes') ?: array(); $childNodeConfiguration = []; foreach ($this->getConfiguration('childNodes') as $name => $configuration) { $childNodeConfiguration[Utility::renderValidNodeName($name)] = $configuration; } $childNodeConstraintConfiguration = ObjectAccess::getPropertyPath($childNodeConfiguration, $childNodeName . '.constraints.nodeTypes') ?: array(); $constraints = Arrays::arrayMergeRecursiveOverrule($constraints, $childNodeConstraintConfiguration); return $this->isNodeTypeAllowedByConstraints($nodeType, $constraints); }
/** * Generate possible node name. When an idealNodeName is given then this is put into a valid format for a node name, * otherwise a random node name in the form "node-alphanumeric" is generated. * * @param string $idealNodeName * @return string */ protected function generatePossibleNodeName($idealNodeName = null) { if ($idealNodeName !== null) { $possibleNodeName = \TYPO3\TYPO3CR\Utility::renderValidNodeName($idealNodeName); } else { $possibleNodeName = NodePaths::generateRandomNodeName(); } return $possibleNodeName; }
/** * Get the name of this node template. * * If a name has been set using setName(), it is returned. If not, but the * template has a (non-empty) title property, this property is used to * generate a valid name. As a last resort a random name is returned (in * the form "nameXXXXX"). * * @return string * @api */ public function getName() { if ($this->name !== NULL) { return $this->name; } if ($this->hasProperty('title') && strlen($this->getProperty('title')) > 0) { return \TYPO3\TYPO3CR\Utility::renderValidNodeName($this->getProperty('title')); } return uniqid('node'); }
/** * Returns a camelcase version of $name with the first letter uppercase. * * @param string $name * @return string */ public static function renderValidName($name) { return preg_replace('/\\s+/', '', ucwords(str_replace('-', ' ', \TYPO3\TYPO3CR\Utility::renderValidNodeName($name)))); }
/** * @test * @dataProvider sourcesAndNodeNames */ public function renderValidNodeNameWorks($source, $expectedNodeName) { $this->assertEquals($expectedNodeName, Utility::renderValidNodeName($source)); }
/** * @param Account $account * @param NodeInterface $userStorageNode * @param PersonDto $person * @return NodeInterface|string */ protected function createProfileNode(Account $account, NodeInterface $userStorageNode, PersonDto $person) { try { $profileNode = $this->findProfileNode($person->getEmailAddress()); if ($profileNode === NULL) { $properties = ['title' => $person->getFirstName() . ' ' . $person->getLastName(), 'firstName' => $person->getFirstName(), 'lastName' => $person->getLastName(), 'address' => $person->getAddress(), 'zipCode' => $person->getZipCode(), 'city' => $person->getCity(), 'emailAddress' => $person->getEmailAddress(), 'phone' => $person->getPhone(), 'dateOfBirth' => $person->getDateOfBirth(), 'jiuJitsu' => $person->getJiuJitsu(), 'buJitsuDo' => $person->getBuJitsuDo(), 'jiuJitsuDegree' => $person->getJiuJitsuDegree(), 'buJitsuDoDegree' => $person->getBuJitsuDoDegree(), 'gender' => $person->getGender()]; if ($person->getFirstName() && $person->getLastName()) { $nodeName = $person->getFirstName() . ' ' . $person->getLastName(); } $idealNodeName = Utility::renderValidNodeName(isset($nodeName) ? $nodeName : uniqid('node')); $idealNodeName = htmlspecialchars($idealNodeName, ENT_NOQUOTES, 'UTF-8'); $profileNode = $this->nodeWriteRepository->createChildNode($userStorageNode, $idealNodeName, 'BuJitsuDo.Authentication:Person', $properties); if ($person->getImage() instanceof Image) { $profileNode = $this->profileService->setImageToNode($profileNode, $person->getImage(), $person->getFirstName(), 'Profile images'); } } $account->getParty()->getPreferences()->set('profileNodeIdentifier', $profileNode->getIdentifier()); $this->partyRepository->update($account->getParty()); $this->persistenceManager->persistAll(); $this->emitPersonCreated($profileNode); return $profileNode; } catch (\Exception $exception) { $this->systemLogger->log('Profile node could not be created because: ' . $exception->getMessage(), LOG_CRIT); return $exception->getMessage(); } }
/** * @param string $idealNodeName * @param NodeInterface $referenceNode * @return string */ protected function getFreeNodeName($idealNodeName, NodeInterface $referenceNode) { $idealNodeName = NodeUtility::renderValidNodeName($idealNodeName); $possibleNodeName = $idealNodeName; $counter = 1; while ($referenceNode->getNode($possibleNodeName) !== null) { $possibleNodeName = $idealNodeName . '-' . $counter; $counter++; } return $possibleNodeName; }