/**
* Publishes the given node to the specified target workspace. If no workspace is specified, the base workspace
* is assumed.
*
* If the given node is a Document or has ContentCollection child nodes, these nodes are published as well.
*
* @param NodeInterface $node
* @param Workspace $targetWorkspace If not set the base workspace is assumed to be the publishing target
* @return void
* @api
*/
public function publishNode(NodeInterface $node, Workspace $targetWorkspace = null)
{
if ($targetWorkspace === null) {
$targetWorkspace = $node->getWorkspace()->getBaseWorkspace();
}
if (!$targetWorkspace instanceof Workspace) {
return;
}
$nodes = array($node);
$nodeType = $node->getNodeType();
if ($nodeType->isOfType('Neos.Neos:Document') || $nodeType->hasConfiguration('childNodes')) {
foreach ($node->getChildNodes('Neos.Neos:ContentCollection') as $contentCollectionNode) {
array_push($nodes, $contentCollectionNode);
}
}
$sourceWorkspace = $node->getWorkspace();
$sourceWorkspace->publishNodes($nodes, $targetWorkspace);
$this->emitNodePublished($node, $targetWorkspace);
}