Neos\ContentRepository\Utility::renderValidNodeName PHP Method

renderValidNodeName() public static method

Transforms a text (for example a node title) into a valid node name by removing invalid characters and transliterating special characters if possible.
public static renderValidNodeName ( string $name ) : string
$name string The possibly invalid node name
return string A valid node name
    public static function renderValidNodeName($name)
    {
        // Check if name already match name pattern to prevent unnecessary transliteration
        if (preg_match(NodeInterface::MATCH_PATTERN_NAME, $name) === 1) {
            return $name;
        }
        // Transliterate (transform 北京 to 'Bei Jing')
        $name = Transliterator::transliterate($name);
        // Urlization (replace spaces with dash, special special characters)
        $name = Transliterator::urlize($name);
        // Ensure only allowed characters are left
        $name = preg_replace('/[^a-z0-9\\-]/', '', $name);
        return $name;
    }

Usage Example

 /**
  * 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);
 }
All Usage Examples Of Neos\ContentRepository\Utility::renderValidNodeName