/** * Recursive function for fetching all node type names * * @param NodeType $nodeType * @param array $nodeTypeNames * @return void */ protected function extractNodeTypeNamesAndSupertypesInternal(NodeType $nodeType, array &$nodeTypeNames) { $nodeTypeNames[$nodeType->getName()] = $nodeType->getName(); foreach ($nodeType->getDeclaredSuperTypes() as $superType) { $this->extractNodeTypeNamesAndSupertypesInternal($superType, $nodeTypeNames); } }
/** * @test */ public function nodeTypesCanHaveAnyNumberOfSuperTypes() { $baseType = new NodeType('TYPO3.TYPO3CR:Base', array(), array()); $folderType = new NodeType('TYPO3.TYPO3CR.Testing:Document', array($baseType), array()); $hideableNodeType = new NodeType('TYPO3.TYPO3CR.Testing:HideableContent', array(), array()); $pageType = new NodeType('TYPO3.TYPO3CR.Testing:Page', array($folderType, $hideableNodeType), array()); $this->assertEquals(array($folderType, $hideableNodeType), $pageType->getDeclaredSuperTypes()); $this->assertTrue($pageType->isOfType('TYPO3.TYPO3CR.Testing:Page')); $this->assertTrue($pageType->isOfType('TYPO3.TYPO3CR.Testing:HideableContent')); $this->assertTrue($pageType->isOfType('TYPO3.TYPO3CR.Testing:Document')); $this->assertTrue($pageType->isOfType('TYPO3.TYPO3CR:Base')); $this->assertFalse($pageType->isOfType('TYPO3.TYPO3CR:Exotic')); }
/** * @param NodeType $nodeType * @return array<NodeType> */ protected function getAllImplementedNodeTypes(NodeType $nodeType) { $types = array($nodeType); foreach ($nodeType->getDeclaredSuperTypes() as $superType) { $types = array_merge($types, $this->getAllImplementedNodeTypes($superType)); } return $types; }
/** * This method traverses the given node type to find the first super type that matches the constraint node type. * In case the hierarchy has more than one way of finding a path to the node type it's not taken into account, * since the first matched is returned. This is accepted on purpose for performance reasons and due to the fact * that such hierarchies should be avoided. * * @param NodeType $currentNodeType * @param string $constraintNodeTypeName * @param integer $distance * @return integer or NULL if no NodeType matched */ protected function traverseSuperTypes(NodeType $currentNodeType, $constraintNodeTypeName, $distance) { if ($currentNodeType->getName() === $constraintNodeTypeName) { return $distance; } $distance++; foreach ($currentNodeType->getDeclaredSuperTypes() as $superType) { $result = $this->traverseSuperTypes($superType, $constraintNodeTypeName, $distance); if ($result !== null) { return $result; } } return null; }
/** * @param string $nodeTypeName * @param NodeType $nodeType * @return void */ protected function readNodeTypeConfiguration($nodeTypeName, NodeType $nodeType) { $nodeTypeConfiguration = $nodeType->getFullConfiguration(); $this->superTypeConfiguration['typo3:' . $nodeTypeName] = array(); /** @var NodeType $superType */ foreach ($nodeType->getDeclaredSuperTypes() as $superType) { $this->superTypeConfiguration['typo3:' . $nodeTypeName][] = 'typo3:' . $superType->getName(); } $nodeTypeProperties = array(); if (isset($nodeTypeConfiguration['properties'])) { foreach ($nodeTypeConfiguration['properties'] as $property => $propertyConfiguration) { // TODO Make sure we can configure the range for all multi column elements to define what types a column may contain $this->addProperty('typo3:' . $nodeTypeName, 'typo3:' . $property, $propertyConfiguration); $nodeTypeProperties[] = 'typo3:' . $property; } } $metadata = array(); $metaDataPropertyIndexes = array('ui'); foreach ($metaDataPropertyIndexes as $propertyName) { if (isset($nodeTypeConfiguration[$propertyName])) { $metadata[$propertyName] = $nodeTypeConfiguration[$propertyName]; } } if ($nodeType->isAbstract()) { $metadata['abstract'] = true; } $this->types['typo3:' . $nodeTypeName] = (object) array('label' => $nodeType->getLabel() ?: $nodeTypeName, 'id' => 'typo3:' . $nodeTypeName, 'properties' => array(), 'specific_properties' => $nodeTypeProperties, 'subtypes' => array(), 'metadata' => (object) $metadata, 'supertypes' => $this->superTypeConfiguration['typo3:' . $nodeTypeName], 'url' => 'http://www.typo3.org/ns/2012/Flow/Packages/Neos/Content/', 'ancestors' => array(), 'comment' => '', 'comment_plain' => ''); }