Neos\ContentRepository\Domain\Service\NodeTypeManager::getNodeType PHP Method

getNodeType() public method

Returns the specified node type (which could be abstract)
public getNodeType ( string $nodeTypeName ) : NodeType
$nodeTypeName string
return Neos\ContentRepository\Domain\Model\NodeType or NULL
    public function getNodeType($nodeTypeName)
    {
        if ($this->cachedNodeTypes === array()) {
            $this->loadNodeTypes();
        }
        if (isset($this->cachedNodeTypes[$nodeTypeName])) {
            return $this->cachedNodeTypes[$nodeTypeName];
        }
        if ($this->fallbackNodeTypeName === null) {
            throw new NodeTypeNotFoundException(sprintf('The node type "%s" is not available and no fallback NodeType is configured.', $nodeTypeName), 1316598370);
        }
        if (!$this->hasNodeType($this->fallbackNodeTypeName)) {
            throw new NodeTypeNotFoundException(sprintf('The node type "%s" is not available and the configured fallback NodeType "%s" is not available.', $nodeTypeName, $this->fallbackNodeTypeName), 1438166322);
        }
        return $this->getNodeType($this->fallbackNodeTypeName);
    }

Usage Example

 /**
  * 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;
 }
All Usage Examples Of Neos\ContentRepository\Domain\Service\NodeTypeManager::getNodeType