/** * Matches if the selected node belongs to one of the given $workspaceNames * * Example: isInWorkspace(['live', 'user-admin']) matches if the selected node is in one of the workspaces "user-admin" or "live" * * @param array $workspaceNames An array of workspace names, e.g. ["live", "user-admin"] * @return boolean TRUE if the selected node matches the $workspaceNames, otherwise FALSE */ public function isInWorkspace($workspaceNames) { if ($this->node === null) { return true; } return in_array($this->node->getWorkspace()->getName(), $workspaceNames); }
/** * 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); }
/** * Collects metadata attributes used to allow editing of the node in the Neos backend. * * @param array $attributes * @param NodeInterface $node * @return array */ protected function addGenericEditingMetadata(array $attributes, NodeInterface $node) { $attributes['typeof'] = 'typo3:' . $node->getNodeType()->getName(); $attributes['about'] = $node->getContextPath(); $attributes['data-node-_identifier'] = $node->getIdentifier(); $attributes['data-node-__workspace-name'] = $node->getWorkspace()->getName(); $attributes['data-node-__label'] = $node->getLabel(); if ($node->getNodeType()->isOfType('Neos.Neos:ContentCollection')) { $attributes['rel'] = 'typo3:content-collection'; } // these properties are needed together with the current NodeType to evaluate Node Type Constraints // TODO: this can probably be greatly cleaned up once we do not use CreateJS or VIE anymore. if ($node->getParent()) { $attributes['data-node-__parent-node-type'] = $node->getParent()->getNodeType()->getName(); } if ($node->isAutoCreated()) { $attributes['data-node-_name'] = $node->getName(); $attributes['data-node-_is-autocreated'] = 'true'; } if ($node->getParent() && $node->getParent()->isAutoCreated()) { $attributes['data-node-_parent-is-autocreated'] = 'true'; // we shall only add these properties if the parent is actually auto-created; as the Node-Type-Switcher in the UI relies on that. $attributes['data-node-__parent-node-name'] = $node->getParent()->getName(); $attributes['data-node-__grandparent-node-type'] = $node->getParent()->getParent()->getNodeType()->getName(); } return $attributes; }
/** * Method which does the actual work of discarding, includes a protection against endless recursions and * multiple discarding of the same node. * * @param NodeInterface $node The node to discard * @param array &$alreadyDiscardedNodeIdentifiers List of node identifiers which already have been discarded during one discardNode() run * @return void * @throws \Neos\ContentRepository\Exception\WorkspaceException */ protected function doDiscardNode(NodeInterface $node, array &$alreadyDiscardedNodeIdentifiers = []) { if ($node->getWorkspace()->getBaseWorkspace() === null) { throw new WorkspaceException('Nodes in a in a workspace without a base workspace cannot be discarded.', 1395841899); } if ($node->getPath() === '/') { return; } if (array_search($node->getIdentifier(), $alreadyDiscardedNodeIdentifiers) !== false) { return; } $alreadyDiscardedNodeIdentifiers[] = $node->getIdentifier(); $possibleShadowNodeData = $this->nodeDataRepository->findOneByMovedTo($node->getNodeData()); if ($possibleShadowNodeData instanceof NodeData) { if ($possibleShadowNodeData->getMovedTo() !== null) { $parentBasePath = $node->getPath(); $affectedChildNodeDataInSameWorkspace = $this->nodeDataRepository->findByParentAndNodeType($parentBasePath, null, $node->getWorkspace(), null, false, true); foreach ($affectedChildNodeDataInSameWorkspace as $affectedChildNodeData) { /** @var NodeData $affectedChildNodeData */ $affectedChildNode = $this->nodeFactory->createFromNodeData($affectedChildNodeData, $node->getContext()); $this->doDiscardNode($affectedChildNode, $alreadyDiscardedNodeIdentifiers); } } $this->nodeDataRepository->remove($possibleShadowNodeData); } $this->nodeDataRepository->remove($node); $this->emitNodeDiscarded($node); }
/** * Retrieves the given node's corresponding node in the base workspace (that is, which would be overwritten if the * given node would be published) * * @param NodeInterface $modifiedNode * @return NodeInterface */ protected function getOriginalNode(NodeInterface $modifiedNode) { $baseWorkspaceName = $modifiedNode->getWorkspace()->getBaseWorkspace()->getName(); $contextProperties = $modifiedNode->getContext()->getProperties(); $contextProperties['workspaceName'] = $baseWorkspaceName; $contentContext = $this->contextFactory->create($contextProperties); return $contentContext->getNodeByIdentifier($modifiedNode->getIdentifier()); }
/** * Publishes the given node to the target workspace. * * The specified workspace must be a base workspace of this workspace. * * @param NodeInterface $node The node to publish * @param Workspace $targetWorkspace The workspace to publish to * @return void * @api */ public function publishNode(NodeInterface $node, Workspace $targetWorkspace) { if ($this->baseWorkspace === null) { return; } if ($node->getWorkspace() !== $this) { return; } // Might happen if a node which has been published during an earlier call of publishNode() is attempted to // be published again: if ($node->getWorkspace() === $targetWorkspace) { return; } $this->verifyPublishingTargetWorkspace($targetWorkspace); $this->emitBeforeNodePublishing($node, $targetWorkspace); if ($node->getPath() === '/') { return; } $targetNodeData = $this->findNodeDataInTargetWorkspace($node, $targetWorkspace); $matchingNodeVariantExistsInTargetWorkspace = $targetNodeData !== null && $targetNodeData->getDimensionValues() === $node->getDimensions(); if ($matchingNodeVariantExistsInTargetWorkspace) { $this->replaceNodeData($node, $targetNodeData); } else { $this->moveNodeVariantToTargetWorkspace($node, $targetWorkspace); } $this->emitAfterNodePublishing($node, $targetWorkspace); }