public registerNodeTypesCnd ( string $cnd, boolean $allowUpdate ) : boolean | Iterator | ||
$cnd | string | a string with cnd information |
$allowUpdate | boolean | whether to fail if node already exists or to update it |
return | boolean | Iterator | true on success or \Iterator over the registered node types if repository is not able to process CND directly |
public function registerNodeTypesCnd($cnd, $allowUpdate)
{
if ($this->transport instanceof NodeTypeCndManagementInterface) {
return $this->transport->registerNodeTypesCnd($cnd, $allowUpdate);
}
if ($this->transport instanceof NodeTypeManagementInterface) {
$workspace = $this->session->getWorkspace();
$nsRegistry = $workspace->getNamespaceRegistry();
$parser = new CndParser($workspace->getNodeTypeManager());
$res = $parser->parseString($cnd);
$ns = $res['namespaces'];
$types = $res['nodeTypes'];
foreach ($ns as $prefix => $uri) {
$nsRegistry->registerNamespace($prefix, $uri);
}
return $workspace->getNodeTypeManager()->registerNodeTypes($types, $allowUpdate);
}
throw new UnsupportedRepositoryOperationException('Transport does not support registering node types');
}
/** * {@inheritDoc} * * @api */ public function registerNodeTypesCnd($cnd, $allowUpdate) { //set fetched from backend to false to allow to load the new types from backend $fetched = $this->fetchedAllFromBackend; $this->fetchedAllFromBackend = false; $this->objectManager->registerNodeTypesCnd($cnd, $allowUpdate); //parse out type names and fetch types to return definitions of the new nodes preg_match_all('/\\[([^\\]]*)\\]/', $cnd, $names); $types = array(); foreach ($names[1] as $name) { $types[$name] = $this->getNodeType($name); } $this->fetchedAllFromBackend = $fetched; return $types; }