Returns the specified node type (which could be abstract)
public getNodeType ( string $nodeTypeName ) : |
||
$nodeTypeName | string | |
Результат | or NULL |
/** * 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('Neos.Neos:Document') && !isset($nodeData['properties']['uriPathSegment']) && isset($nodeData['properties']['title'])) { $nodeData['properties']['uriPathSegment'] = $this->nodeUriPathSegmentGenerator->generateUriPathSegment($referenceNode, $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; }
/** * @test */ public function readNodeTypeConfigurationFillsTypeAndPropertyConfiguration() { $this->assertEquals($this->vieSchemaBuilder->_get('superTypeConfiguration'), array()); $this->assertEquals($this->vieSchemaBuilder->_get('types'), array()); $this->assertEquals($this->vieSchemaBuilder->_get('properties'), array()); $this->vieSchemaBuilder->_call('readNodeTypeConfiguration', 'Neos.Neos:TextWithImage', $this->nodeTypeManager->getNodeType('Neos.Neos:TextWithImage')); $this->assertEquals(array('typo3:Neos.Neos:TextWithImage' => array('typo3:Neos.Neos:Text')), $this->vieSchemaBuilder->_get('superTypeConfiguration')); $this->arrayHasKey('typo3:Neos.Neos:TextWithImage', $this->vieSchemaBuilder->_get('types')); $this->assertEquals(4, count($this->vieSchemaBuilder->_get('properties'))); }
/** * Repair inconsistent nodes * * This command analyzes and repairs the node tree structure and individual nodes * based on the current node type configuration. * * It is possible to execute only one or more specific checks by providing the <b>--skip</b> * or <b>--only</b> option. See the full description of checks further below for possible check * identifiers. * * The following checks will be performed: * * {pluginDescriptions} * <b>Examples:</b> * * ./flow node:repair * * ./flow node:repair --node-type Neos.NodeTypes:Page * * ./flow node:repair --workspace user-robert --only removeOrphanNodes,removeNodesWithInvalidDimensions * * ./flow node:repair --skip removeUndefinedProperties * * @param string $nodeType Node type name, if empty update all declared node types * @param string $workspace Workspace name, default is 'live' * @param boolean $dryRun Don't do anything, but report actions * @param boolean $cleanup If FALSE, cleanup tasks are skipped * @param string $skip Skip the given check or checks (comma separated) * @param string $only Only execute the given check or checks (comma separated) * @return void */ public function repairCommand($nodeType = null, $workspace = 'live', $dryRun = false, $cleanup = true, $skip = null, $only = null) { $this->pluginConfigurations = self::detectPlugins($this->objectManager); if ($this->workspaceRepository->countByName($workspace) === 0) { $this->outputLine('Workspace "%s" does not exist', array($workspace)); exit(1); } if ($nodeType !== null) { if ($this->nodeTypeManager->hasNodeType($nodeType)) { $nodeType = $this->nodeTypeManager->getNodeType($nodeType); } else { $this->outputLine('Node type "%s" does not exist', array($nodeType)); exit(1); } } if ($dryRun) { $this->outputLine('Dry run, not committing any changes.'); } if (!$cleanup) { $this->outputLine('Omitting cleanup tasks.'); } foreach ($this->pluginConfigurations as $pluginConfiguration) { /** @var NodeCommandControllerPluginInterface $plugin */ $plugin = $pluginConfiguration['object']; $this->outputLine('<b>' . $plugin->getSubCommandShortDescription('repair') . '</b>'); $this->outputLine(); $plugin->invokeSubCommand('repair', $this->output, $nodeType, $workspace, $dryRun, $cleanup, $skip, $only); $this->outputLine(); } $this->outputLine('Node repair finished.'); }
/** * Create a new empty site. * * @param string $packageKey Package Name to create * @param string $siteName Site Name to create * @param string $nodeType NodeType name for the root node to create * @Flow\Validate(argumentName="$packageKey", type="\Neos\Neos\Validation\Validator\PackageKeyValidator") * @return void */ public function createSiteNodeAction($packageKey, $siteName, $nodeType) { $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $siteName); if ($this->siteRepository->findOneByNodeName($nodeName)) { $this->addFlashMessage('Error:A site with siteNodeName "%s" already exists', Message::SEVERITY_ERROR, [$nodeName], 1412372375); $this->redirect('createSiteNode'); } $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType); if ($siteNodeType === null || $siteNodeType->getName() === 'Neos.Neos:FallbackNode') { $this->addFlashMessage('Error: The given node type "%s" was not found', 'Import error', Message::SEVERITY_ERROR, [$nodeType], 1412372375); $this->redirect('createSiteNode'); } if ($siteNodeType->isOfType('Neos.Neos:Document') === false) { $this->addFlashMessage('Error: The given node type "%s" is not based on the superType "%s"', Message::SEVERITY_ERROR, [$nodeType, 'Neos.Neos:Document'], 1412372375); $this->redirect('createSiteNode'); } $rootNode = $this->nodeContextFactory->create()->getRootNode(); // We fetch the workspace to be sure it's known to the persistence manager and persist all // so the workspace and site node are persisted before we import any nodes to it. $rootNode->getContext()->getWorkspace(); $this->persistenceManager->persistAll(); $sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH); if ($sitesNode === null) { $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH)); } $siteNode = $sitesNode->createNode($nodeName, $siteNodeType); $siteNode->setProperty('title', $siteName); $site = new Site($nodeName); $site->setSiteResourcesPackageKey($packageKey); $site->setState(Site::STATE_ONLINE); $site->setName($siteName); $this->siteRepository->add($site); $this->addFlashMessage('Successfully created site "%s" with siteNode "%s", type "%s" and packageKey "%s"', '', null, [$siteName, $nodeName, $nodeType, $packageKey], 1412372266); $this->unsetLastVisitedNodeAndRedirect('index'); }
/** * @test */ public function inheritanceBasedConstraintsWork() { $testingNodeTypeWithSubnodes = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeTypeWithSubnodes'); $testingNodeTypeThatInheritsFromDocumentType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Page'); $nodeWithChildNode = $this->rootNode->createNode('node-with-child-node', $testingNodeTypeWithSubnodes); $nodeWithChildNode->createNode('page', $testingNodeTypeThatInheritsFromDocumentType); $this->assertCount(2, $nodeWithChildNode->getChildNodes()); }
/** * Render the label for the given $nodeTypeName * * @param string $nodeTypeName * @throws NodeTypeNotFoundException * @return string */ public function labelForNodeType($nodeTypeName) { if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) { $explodedNodeTypeName = explode(':', $nodeTypeName); return end($explodedNodeTypeName); } $nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName); return $nodeType->getLabel(); }
/** * @test */ public function getChildNodesWithNodeTypeFilterWorks() { $documentNodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Document'); $headlineNodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Headline'); $imageNodeType = $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Image'); $node = $this->context->getRootNode()->createNode('node-with-child-node', $documentNodeType); $node->createNode('headline', $headlineNodeType); $node->createNode('text', $imageNodeType); $this->assertCount(1, $node->getChildNodes('Neos.ContentRepository.Testing:Headline')); }
/** * @throws \Neos\ContentRepository\Exception\NodeTypeNotFoundException */ protected function createNodesForNodeSearchTest() { $rootNode = $this->context->getRootNode(); $newNode1 = $rootNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeType')); $newNode1->setProperty('test1', 'simpleTestValue'); $newNode2 = $rootNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeType')); $newNode2->setProperty('test2', 'simpleTestValue'); $newNode2 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:NodeType')); $newNode2->setProperty('test1', 'otherValue'); $this->persistenceManager->persistAll(); }
/** * @test */ public function aSingleNodeExportedWithNodeDataExportCanBeImportedWithNodeDataImport() { $originalNode = $this->rootNode->createNode('foo', $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:ImportExport')); $originalNode->setProperty('description', 'Some node with a property'); $originalNode->setProperty('someDate', new \DateTime()); $this->persistenceManager->persistAll(); $exportService = new NodeExportService(); $xml = $exportService->export('/')->outputMemory(); $this->nodeDataRepository->removeAll(); $this->workspaceRepository->removeAll(); $this->saveNodesAndTearDownRootNodeAndRepository(); $this->setUpRootNodeAndRepository(); $importService = new NodeImportService(); $reader = new \XMLReader(); $reader->XML($xml); $importService->import($reader, '/'); $importedNode = $this->rootNode->getNode('foo'); $this->assertNotNull($importedNode, 'Expected node not found'); $this->assertSame($originalNode->getIdentifier(), $importedNode->getIdentifier()); $this->assertSame($originalNode->getProperty('description'), $importedNode->getProperty('description')); $this->assertEquals($originalNode->getProperty('someDate'), $importedNode->getProperty('someDate')); }
/** * Return an array with child nodes which should be automatically created * * @return array the key of this array is the name of the child, and the value its NodeType. * @api */ public function getAutoCreatedChildNodes() { $this->initialize(); if (!isset($this->fullConfiguration['childNodes'])) { return array(); } $autoCreatedChildNodes = array(); foreach ($this->fullConfiguration['childNodes'] as $childNodeName => $childNodeConfiguration) { if (isset($childNodeConfiguration['type'])) { $autoCreatedChildNodes[Utility::renderValidNodeName($childNodeName)] = $this->nodeTypeManager->getNodeType($childNodeConfiguration['type']); } } return $autoCreatedChildNodes; }
/** * Detects the requested node type and returns a corresponding NodeType instance. * * @param string $targetType * @param array $source * @return NodeType */ protected function extractNodeType($targetType, array $source) { if (isset($source['__nodeType'])) { $nodeTypeName = $source['__nodeType']; } else { $matches = array(); preg_match(self::EXTRACT_CONTENT_TYPE_PATTERN, $targetType, $matches); if (isset($matches['nodeType'])) { $nodeTypeName = $matches['nodeType']; } else { $nodeTypeName = 'unstructured'; } } return $this->nodeTypeManager->getNodeType($nodeTypeName); }
/** * Reorder child nodes for the given node type * * @param string $workspaceName * @param boolean $dryRun * @param NodeType $nodeType * @return void */ protected function reorderChildNodesByNodeType($workspaceName, $dryRun, NodeType $nodeType) { $nodeTypes = $this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), false); $nodeTypes[$nodeType->getName()] = $nodeType; if ($this->nodeTypeManager->hasNodeType((string) $nodeType)) { $nodeType = $this->nodeTypeManager->getNodeType((string) $nodeType); $nodeTypeNames[$nodeType->getName()] = $nodeType; } else { $this->output->outputLine('Node type "%s" does not exist', array((string) $nodeType)); exit(1); } /** @var $nodeType NodeType */ foreach ($nodeTypes as $nodeTypeName => $nodeType) { $childNodes = $nodeType->getAutoCreatedChildNodes(); if ($childNodes === array()) { continue; } foreach ($this->getNodeDataByNodeTypeAndWorkspace($nodeTypeName, $workspaceName) as $nodeData) { /** @var NodeInterface $childNodeBefore */ $childNodeBefore = null; $context = $this->nodeFactory->createContextMatchingNodeData($nodeData); $node = $this->nodeFactory->createFromNodeData($nodeData, $context); if (!$node instanceof NodeInterface) { continue; } foreach ($childNodes as $childNodeName => $childNodeType) { $childNode = $node->getNode($childNodeName); if ($childNode) { if ($childNodeBefore) { if ($dryRun === false) { if ($childNodeBefore->getIndex() >= $childNode->getIndex()) { $childNode->moveAfter($childNodeBefore); $this->output->outputLine('Moved node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath())); } } else { $this->output->outputLine('Should move node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath())); } } } else { $this->output->outputLine('Missing child node named "%s" in "%s".', array($childNodeName, $node->getPath())); } $childNodeBefore = $childNode; } } } }
/** * Create a new site * * This command allows to create a blank site with just a single empty document in the default dimension. * The name of the site, the packageKey must be specified. * * If no ``nodeType`` option is specified the command will use `Neos.Neos.NodeTypes:Page` as fallback. The node type * must already exists and have the superType ``Neos.Neos:Document``. * * If no ``nodeName` option is specified the command will create a unique node-name from the name of the site. * If a node name is given it has to be unique for the setup. * * If the flag ``activate` is set to false new site will not be activated. * * @param string $name The name of the site * @param string $packageKey The site package * @param string $nodeType The node type to use for the site node. (Default = Neos.Neos.NodeTypes:Page) * @param string $nodeName The name of the site node. If no nodeName is given it will be determined from the siteName. * @param boolean $inactive The new site is not activated immediately (default = false). * @return void */ public function createCommand($name, $packageKey, $nodeType = 'Neos.Neos.NodeTypes:Page', $nodeName = null, $inactive = false) { if ($nodeName === null) { $nodeName = $this->nodeService->generateUniqueNodeName(SiteService::SITES_ROOT_PATH, $name); } if ($this->siteRepository->findOneByNodeName($nodeName)) { $this->outputLine('<error>A site with siteNodeName "%s" already exists</error>', [$nodeName]); $this->quit(1); } if ($this->packageManager->isPackageAvailable($packageKey) === false) { $this->outputLine('<error>Could not find package "%s"</error>', [$packageKey]); $this->quit(1); } $siteNodeType = $this->nodeTypeManager->getNodeType($nodeType); if ($siteNodeType === null || $siteNodeType->getName() === 'Neos.Neos:FallbackNode') { $this->outputLine('<error>The given node type "%s" was not found</error>', [$nodeType]); $this->quit(1); } if ($siteNodeType->isOfType('Neos.Neos:Document') === false) { $this->outputLine('<error>The given node type "%s" is not based on the superType "%s"</error>', [$nodeType, 'Neos.Neos:Document']); $this->quit(1); } $rootNode = $this->nodeContextFactory->create()->getRootNode(); // We fetch the workspace to be sure it's known to the persistence manager and persist all // so the workspace and site node are persisted before we import any nodes to it. $rootNode->getContext()->getWorkspace(); $this->persistenceManager->persistAll(); $sitesNode = $rootNode->getNode(SiteService::SITES_ROOT_PATH); if ($sitesNode === null) { $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH)); } $siteNode = $sitesNode->createNode($nodeName, $siteNodeType); $siteNode->setProperty('title', $name); $site = new Site($nodeName); $site->setSiteResourcesPackageKey($packageKey); $site->setState($inactive ? Site::STATE_OFFLINE : Site::STATE_ONLINE); $site->setName($name); $this->siteRepository->add($site); $this->outputLine('Successfully created site "%s" with siteNode "%s", type "%s", packageKey "%s" and state "%s"', [$name, $nodeName, $nodeType, $packageKey, $inactive ? 'offline' : 'online']); }
/** * Converts the specified $source into a Node. * * If $source is a UUID it is expected to refer to the identifier of a NodeData record of the "live" workspace * * Otherwise $source has to be a valid node path: * * 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 PropertyMappingConfigurationInterface $configuration * @return mixed An object or \Neos\Error\Messages\Error if the input format is not supported or could not be converted for other reasons * @throws NodeException */ 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; }
/** * @test * @expectedException \Neos\ContentRepository\Exception\NodeTypeIsFinalException */ public function getNodeTypeThrowsExceptionIfFinalNodeTypeIsSubclassed() { $nodeTypesFixture = array('Neos.ContentRepository.Testing:Base' => array('final' => true), 'Neos.ContentRepository.Testing:Sub' => array('superTypes' => array('Neos.ContentRepository.Testing:Base' => true))); $this->prepareNodeTypeManager($nodeTypesFixture); $this->nodeTypeManager->getNodeType('Neos.ContentRepository.Testing:Sub'); }
/** * Returns the node type of this node. * * @return \Neos\ContentRepository\Domain\Model\NodeType */ public function getNodeType() { return $this->nodeTypeManager->getNodeType($this->nodeType); }
/** * Change the Node Type on the given node. * * @param NodeData $node * @return void */ public function execute(NodeData $node) { $nodeType = $this->nodeTypeManager->getNodeType($this->newType); $node->setNodeType($nodeType); }