/** * @Flow\Before("method(TYPO3\Neos\Controller\Backend\ContentController->uploadAssetAction())") * @param JoinPointInterface $joinPoint The current join point * @return void */ public function rewriteSiteAssetCollection(JoinPointInterface $joinPoint) { if ($this->lookupNodeFilter === NULL || $this->lookupPropertyName === NULL) { return; } /** @var ContentController $contentController */ $contentController = $joinPoint->getProxy(); /** @var ActionRequest $actionRequest */ $actionRequest = ObjectAccess::getProperty($contentController, 'request', TRUE); $nodeContextPath = $actionRequest->getInternalArgument('__node'); if ($nodeContextPath === NULL) { return; } $node = $this->propertyMapper->convert($nodeContextPath, NodeInterface::class); $flowQuery = new FlowQuery(array($node)); /** @var NodeInterface $documentNode */ $documentNode = $flowQuery->closest($this->lookupNodeFilter)->get(0); if (!$documentNode->hasProperty($this->lookupPropertyName)) { return; } /** @var AssetCollection $assetCollection */ $assetCollection = $this->assetCollectionRepository->findByIdentifier($documentNode->getProperty($this->lookupPropertyName)); if ($assetCollection === NULL) { return; } /** @var Asset $asset */ $asset = $joinPoint->getMethodArgument('asset'); $assetCollection->addAsset($asset); $this->assetCollectionRepository->update($assetCollection); }
/** * Tests on a tree: * * a * a1 * a2 * b (TestingNodeType) * b1 (TestingNodeType) * b1a * b2 * b3 (TestingNodeTypeWithSubnodes) * b3a (TestingNodeType) * b3b * * @test * @dataProvider closestOperationDataProvider */ public function closestOperationTests($currentNodePath, $nodeTypeFilter, $expectedNodePath) { $nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager'); $testNodeType1 = $nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeType'); $testNodeType2 = $nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeTypeWithSubnodes'); $rootNode = $this->node->getNode('/'); $nodeA = $rootNode->createNode('a'); $nodeA->createNode('a1'); $nodeA->createNode('a2'); $nodeB = $rootNode->createNode('b', $testNodeType1); $nodeB1 = $nodeB->createNode('b1', $testNodeType1); $nodeB1->createNode('b1a'); $nodeB->createNode('b2'); $nodeB3 = $nodeB->createNode('b3', $testNodeType2); $nodeB3->createNode('b3a', $testNodeType1); $nodeB3->createNode('b3b'); $currentNode = $rootNode->getNode($currentNodePath); $q = new FlowQuery(array($currentNode)); $actualNode = $q->closest($nodeTypeFilter)->get(0); if ($expectedNodePath === null) { if ($actualNode !== null) { $this->fail('Expected resulting node to be NULL'); } $this->assertNull($actualNode); } else { $this->assertSame($expectedNodePath, $actualNode->getPath()); } }
/** * Helper method to retrieve the closest document for a node * * @param NodeInterface $node * @return NodeInterface */ public function getClosestDocument(NodeInterface $node) { if ($node->getNodeType()->isOfType('TYPO3.Neos:Document')) { return $node; } $flowQuery = new FlowQuery(array($node)); return $flowQuery->closest('[instanceof TYPO3.Neos:Document]')->get(0); }
/** * @param array $nodes */ public function assignNodes(array $nodes) { $data = array(); foreach ($nodes as $node) { if ($node->getPath() !== '/') { $q = new FlowQuery(array($node)); $closestDocumentNode = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); if ($closestDocumentNode !== NULL) { $data[] = array('nodeContextPath' => $node->getContextPath(), 'documentNodeContextPath' => $closestDocumentNode->getContextPath()); } else { $this->systemLogger->log('You have a node that is no longer connected to a parent. Path: ' . $node->getPath() . ' (Identifier: ' . $node->getIdentifier() . ')'); } } } $this->assign('value', array('data' => $data, 'success' => TRUE)); }
/** * @Flow\Around("method(TYPO3\Flow\Mvc\Routing\UriBuilder->uriFor())") * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point * @return string The result of the target method if it has not been intercepted */ public function rewritePluginViewUris(JoinPointInterface $joinPoint) { /** @var \TYPO3\Flow\Mvc\ActionRequest $request */ $request = $joinPoint->getProxy()->getRequest(); $arguments = $joinPoint->getMethodArguments(); $currentNode = $request->getInternalArgument('__node'); if (!$request->getMainRequest()->hasArgument('node') || !$currentNode instanceof Node) { return $joinPoint->getAdviceChain()->proceed($joinPoint); } $currentNode = $request->getInternalArgument('__node'); $controllerObjectName = $this->getControllerObjectName($request, $arguments); $actionName = $arguments['actionName'] !== null ? $arguments['actionName'] : $request->getControllerActionName(); $targetNode = $this->pluginService->getPluginNodeByAction($currentNode, $controllerObjectName, $actionName); // TODO override namespace $q = new FlowQuery(array($targetNode)); $pageNode = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); $result = $this->generateUriForNode($request, $joinPoint, $pageNode); return $result; }
/** * Fetch all master plugins that are available in the current * workspace. * * @param string $workspaceName Name of the workspace to use for querying the node * @param array $dimensions Optional list of dimensions and their values which should be used for querying the specified node * @return string JSON encoded array of node path => label */ public function masterPluginsAction($workspaceName = 'live', array $dimensions = array()) { $this->response->setHeader('Content-Type', 'application/json'); $contentContext = $this->createContentContext($workspaceName, $dimensions); $pluginNodes = $this->pluginService->getPluginNodesWithViewDefinitions($contentContext); $masterPlugins = array(); if (is_array($pluginNodes)) { /** @var $pluginNode NodeInterface */ foreach ($pluginNodes as $pluginNode) { if ($pluginNode->isRemoved()) { continue; } $q = new FlowQuery(array($pluginNode)); $page = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); if ($page === null) { continue; } $translationHelper = new TranslationHelper(); $masterPlugins[$pluginNode->getIdentifier()] = $translationHelper->translate('masterPlugins.nodeTypeOnPageLabel', null, ['nodeTypeName' => $translationHelper->translate($pluginNode->getNodeType()->getLabel()), 'pageLabel' => $page->getLabel()], 'Main', 'TYPO3.Neos'); } } return json_encode((object) $masterPlugins); }
/** * Takes care of creating a redirect to properly render the collection the given node is in. * * @param NodeInterface $node * @param string $typoScriptPath * @return string */ protected function redirectToRenderNode(NodeInterface $node, $typoScriptPath) { $q = new FlowQuery(array($node)); $closestContentCollection = $q->closest('[instanceof TYPO3.Neos:ContentCollection]')->get(0); $closestDocumentNode = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); $this->redirect('show', 'Frontend\\Node', 'TYPO3.Neos', ['node' => $closestDocumentNode, '__nodeContextPath' => $closestContentCollection->getContextPath(), '__affectedNodeContextPath' => $node->getContextPath(), '__typoScriptPath' => $typoScriptPath], 0, 303, 'html'); }
/** * Creates a new node beneath $parent * * @param NodeInterface $parent * @return NodeInterface */ protected function createNode(NodeInterface $parent) { $nodeType = $this->getNodeType(); $name = $this->getName() ?: $this->nodeService->generateUniqueNodeName($parent->getPath()); $node = $parent->createNode($name, $nodeType); $this->applyNodeCreationHandlers($node); $this->persistenceManager->persistAll(); if ($nodeType->isOfType('TYPO3.Neos:Content') && ($this->getParentDomAddress() || $this->getSiblingDomAddress())) { if ($parent->getNodeType()->isOfType('TYPO3.Neos:ContentCollection')) { $renderContentOutOfBand = new RenderContentOutOfBand(); $renderContentOutOfBand->setNode($node); $renderContentOutOfBand->setParentDomAddress($this->getParentDomAddress()); $renderContentOutOfBand->setSiblingDomAddress($this->getSiblingDomAddress()); $renderContentOutOfBand->setMode($this->getMode()); $this->feedbackCollection->add($renderContentOutOfBand); } else { $flowQuery = new FlowQuery(array($node)); $closestDocument = $flowQuery->closest('[instanceof TYPO3.Neos:Document]')->get(0); $reloadDocument = new ReloadDocument(); $reloadDocument->setDocument($closestDocument); $this->feedbackCollection->add($reloadDocument); } } $updateNodeInfo = new UpdateNodeInfo(); $updateNodeInfo->setNode($node); $this->feedbackCollection->add($updateNodeInfo); return $node; }
/** * Builds an array of changes for sites in the given workspace * * @param Workspace $selectedWorkspace * @return array */ protected function computeSiteChanges(Workspace $selectedWorkspace) { $siteChanges = []; foreach ($this->publishingService->getUnpublishedNodes($selectedWorkspace) as $node) { /** @var NodeInterface $node */ if (!$node->getNodeType()->isOfType('TYPO3.Neos:ContentCollection')) { $pathParts = explode('/', $node->getPath()); if (count($pathParts) > 2) { $siteNodeName = $pathParts[2]; $q = new FlowQuery([$node]); $document = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); // FIXME: $document will be null if we have a broken root line for this node. This actually should never happen, but currently can in some scenarios. if ($document !== null) { $documentPath = implode('/', array_slice(explode('/', $document->getPath()), 3)); $relativePath = str_replace(sprintf(SiteService::SITES_ROOT_PATH . '/%s/%s', $siteNodeName, $documentPath), '', $node->getPath()); if (!isset($siteChanges[$siteNodeName]['siteNode'])) { $siteChanges[$siteNodeName]['siteNode'] = $this->siteRepository->findOneByNodeName($siteNodeName); } $siteChanges[$siteNodeName]['documents'][$documentPath]['documentNode'] = $document; $change = ['node' => $node]; if ($node->getNodeType()->isOfType('TYPO3.Neos:Node')) { $change['configuration'] = $node->getNodeType()->getFullConfiguration(); } $siteChanges[$siteNodeName]['documents'][$documentPath]['changes'][$relativePath] = $change; } } } } $liveContext = $this->contextFactory->create(['workspaceName' => 'live']); ksort($siteChanges); foreach ($siteChanges as $siteKey => $site) { foreach ($site['documents'] as $documentKey => $document) { foreach ($document['changes'] as $changeKey => $change) { $liveNode = $liveContext->getNodeByIdentifier($change['node']->getIdentifier()); $siteChanges[$siteKey]['documents'][$documentKey]['changes'][$changeKey]['isNew'] = is_null($liveNode); $siteChanges[$siteKey]['documents'][$documentKey]['changes'][$changeKey]['isMoved'] = $liveNode && $change['node']->getPath() !== $liveNode->getPath(); } } ksort($siteChanges[$siteKey]['documents']); } return $siteChanges; }
/** * Get Related Nodes for an asset * * @param Asset $asset * @return void */ public function relatedNodesAction(Asset $asset) { $userWorkspace = $this->userService->getPersonalWorkspace(); $relatedNodes = []; foreach ($this->getRelatedNodes($asset) as $relatedNodeData) { $accessible = $this->domainUserService->currentUserCanReadWorkspace($relatedNodeData->getWorkspace()); if ($accessible) { $context = $this->createContextMatchingNodeData($relatedNodeData); } else { $context = $this->createContentContext($userWorkspace->getName()); } $site = $context->getCurrentSite(); $node = $this->nodeFactory->createFromNodeData($relatedNodeData, $context); $flowQuery = new FlowQuery([$node]); /** @var Node $documentNode */ $documentNode = $flowQuery->closest('[instanceof TYPO3.Neos:Document]')->get(0); $documentNodeIdentifier = $documentNode instanceof NodeInterface ? $documentNode->getIdentifier() : null; $relatedNodes[$site->getNodeName()]['site'] = $site; $relatedNodes[$site->getNodeName()]['documentNodes'][$documentNodeIdentifier]['node'] = $documentNode; $relatedNodes[$site->getNodeName()]['documentNodes'][$documentNodeIdentifier]['nodes'][] = ['node' => $node, 'nodeData' => $relatedNodeData, 'contextDocumentNode' => $documentNode, 'accessible' => $accessible]; } $this->view->assignMultiple(['asset' => $asset, 'relatedNodes' => $relatedNodes, 'contentDimensions' => $this->contentDimensionPresetSource->getAllPresets(), 'userWorkspace' => $userWorkspace]); }
/** * Fetch all master plugins that are available in the current * workspace. * * @param NodeInterface $node * @return string JSON encoded array of node path => label */ public function masterPluginsAction(NodeInterface $node) { $this->response->setHeader('Content-Type', 'application/json'); $pluginNodes = $this->pluginService->getPluginNodesWithViewDefinitions($node->getContext()); $masterPlugins = array(); if (is_array($pluginNodes)) { /** @var $pluginNode NodeInterface */ foreach ($pluginNodes as $pluginNode) { if ($pluginNode->isRemoved()) { continue; } $q = new FlowQuery(array($pluginNode)); $page = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); if ($page === NULL) { continue; } $masterPlugins[$pluginNode->getPath()] = sprintf('"%s" on page "%s"', $pluginNode->getNodeType()->getLabel(), $page->getLabel()); } } return json_encode((object) $masterPlugins); }
/** * @param NodeInterface $node * @return NodeInterface */ public function render(NodeInterface $node) { $flowQuery = new FlowQuery(array($node)); return $flowQuery->closest('[instanceof TYPO3.Neos:Document]')->get(0); }
/** * Display a list of unpublished content * * @param Workspace $workspace * @return void * @todo Pagination * @todo Tree filtering + level limit * @todo Search field * @todo Difference mechanism */ public function indexAction(Workspace $workspace = NULL) { if ($workspace === NULL) { $workspace = $this->userService->getUserWorkspace(); } $sites = array(); foreach ($this->publishingService->getUnpublishedNodes($workspace) as $node) { $pathParts = explode('/', $node->getPath()); if (count($pathParts) > 2) { $siteNodeName = $pathParts[2]; $q = new FlowQuery(array($node)); $document = $q->closest('[instanceof TYPO3.Neos:Document]')->get(0); // FIXME: $document will be NULL if we have a broken rootline for this node. This actually should never happen, but currently can in some scenarios. if ($document !== NULL) { $documentPath = implode('/', array_slice(explode('/', $document->getPath()), 3)); $relativePath = str_replace(sprintf('/sites/%s/%s', $siteNodeName, $documentPath), '', $node->getPath()); if (!isset($sites[$siteNodeName]['siteNode'])) { $sites[$siteNodeName]['siteNode'] = $this->siteRepository->findOneByNodeName($siteNodeName); } $sites[$siteNodeName]['documents'][$documentPath]['documentNode'] = $document; $change = array('node' => $node); if ($node->getNodeType()->isOfType('TYPO3.Neos:Node')) { $change['configuration'] = $node->getNodeType()->getFullConfiguration(); } $sites[$siteNodeName]['documents'][$documentPath]['changes'][$relativePath] = $change; } } } $liveContext = $this->contextFactory->create(array('workspaceName' => 'live')); ksort($sites); foreach ($sites as $siteKey => $site) { foreach ($site['documents'] as $documentKey => $document) { foreach ($document['changes'] as $changeKey => $change) { $liveNode = $liveContext->getNodeByIdentifier($change['node']->getIdentifier()); $sites[$siteKey]['documents'][$documentKey]['changes'][$changeKey]['isNew'] = is_null($liveNode); $sites[$siteKey]['documents'][$documentKey]['changes'][$changeKey]['isMoved'] = $liveNode && $change['node']->getPath() !== $liveNode->getPath(); } } ksort($sites[$siteKey]['documents']); } $workspaces = array(); foreach ($this->workspaceRepository->findAll() as $workspaceInstance) { array_push($workspaces, array('workspaceNode' => $workspaceInstance, 'unpublishedNodesCount' => $this->publishingService->getUnpublishedNodesCount($workspaceInstance))); } $this->view->assignMultiple(array('workspace' => $workspace, 'workspaces' => $workspaces, 'sites' => $sites)); }
/** * Returns an array of usage reference objects. * * @param AssetInterface $asset * @return array<\TYPO3\Neos\Domain\Model\Dto\AssetUsageInNodeProperties> * @throws \TYPO3\TYPO3CR\Exception\NodeConfigurationException */ public function getUsageReferences(AssetInterface $asset) { $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset); if (isset($this->firstlevelCache[$assetIdentifier])) { return $this->firstlevelCache[$assetIdentifier]; } $userWorkspace = $this->userService->getPersonalWorkspace(); $relatedNodes = []; foreach ($this->getRelatedNodes($asset) as $relatedNodeData) { $accessible = $this->domainUserService->currentUserCanReadWorkspace($relatedNodeData->getWorkspace()); if ($accessible) { $context = $this->createContextMatchingNodeData($relatedNodeData); } else { $context = $this->createContentContext($userWorkspace->getName()); } $site = $context->getCurrentSite(); $node = $this->nodeFactory->createFromNodeData($relatedNodeData, $context); $flowQuery = new FlowQuery([$node]); /** @var \TYPO3\TYPO3CR\Domain\Model\NodeInterface $documentNode */ $documentNode = $flowQuery->closest('[instanceof TYPO3.Neos:Document]')->get(0); $relatedNodes[] = new AssetUsageInNodeProperties($asset, $site, $documentNode, $node, $accessible); } $this->firstlevelCache[$assetIdentifier] = $relatedNodes; return $this->firstlevelCache[$assetIdentifier]; }
/** * @param NodeInterface $systemNode * @param $ancestorNodeTypeName * @return NodeInterface */ protected function fetchClosestAncestorNode(NodeInterface $systemNode, $ancestorNodeTypeName) { $flowQuery = new FlowQuery([$systemNode]); return $flowQuery->closest('[instanceof ' . $ancestorNodeTypeName . ']')->get(0); }