/**
* Fetch a node type from backend.
*
* Without a filter parameter, this will fetch all node types from the backend.
*
* It is no problem to call this method with null as name, it will remember
* once it fetched all node types and do nothing after that.
*
* On fetch all, already cached node types are kept.
*
* @param string $name type name to fetch. defaults to null which will
* fetch all nodes.
*/
protected function fetchNodeTypes($name = null)
{
if ($this->fetchedAllFromBackend) {
return;
}
if (null !== $name) {
if (!empty($this->primaryTypes[$name]) || !empty($this->mixinTypes[$name])) {
return;
//we already know this node
}
//OPTIMIZE: also avoid trying to fetch nonexisting definitions we already tried to get
$nodetypes = $this->objectManager->getNodeType($name);
} else {
$nodetypes = $this->objectManager->getNodeTypes();
$this->fetchedAllFromBackend = true;
}
foreach ($nodetypes as $nodetype) {
$nodetype = $this->factory->get('NodeType\\NodeType', array($this, $nodetype));
$name = $nodetype->getName();
//do not overwrite existing types. maybe they where changed locally
if (empty($this->primaryTypes[$name]) && empty($this->mixinTypes[$name])) {
$this->addNodeType($nodetype);
}
}
}