/** * @test */ public function linkingServiceUnsetsLastLinkedNodeOnFailure() { $this->linkingService->createNodeUri($this->controllerContext, '/sites/example/home', $this->baseNode); $this->assertNotNull($this->linkingService->getLastLinkedNode()); try { $this->linkingService->createNodeUri($this->controllerContext, '/sites/example/non-existing-node', $this->baseNode); } catch (NeosException $exception) { } $this->assertNull($this->linkingService->getLastLinkedNode()); }
/** * Renders the link. Renders the linked node's label if there's no child content. * * @param mixed $node A node object or a string node path or NULL to resolve the current document node * @param string $format Format to use for the URL, for example "html" or "json" * @param boolean $absolute If set, an absolute URI is rendered * @param array $arguments Additional arguments to be passed to the UriBuilder (for example pagination parameters) * @param string $section The anchor to be added to the URI * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE * @param string $nodeVariableName The variable the node will be assigned to for the rendered child content * @param string $baseNodeName The name of the base node inside the TypoScript context to use for the ContentContext or resolving relative paths * @param boolean $resolveShortcuts INTERNAL Parameter - if FALSE, shortcuts are not redirected to their target. Only needed on rare backend occasions when we want to link to the shortcut itself. * @return string The rendered link * @throws ViewHelperException */ public function render($node = NULL, $format = NULL, $absolute = FALSE, array $arguments = array(), $section = '', $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $baseNodeName = 'documentNode', $nodeVariableName = 'linkedNode', $resolveShortcuts = TRUE) { $baseNode = NULL; if (!$node instanceof NodeInterface) { $view = $this->viewHelperVariableContainer->getView(); if ($view instanceof TypoScriptAwareViewInterface) { $typoScriptObject = $view->getTypoScriptObject(); $currentContext = $typoScriptObject->getTsRuntime()->getCurrentContext(); if (isset($currentContext[$baseNodeName])) { $baseNode = $currentContext[$baseNodeName]; } } } try { $uri = $this->linkingService->createNodeUri($this->controllerContext, $node, $baseNode, $format, $absolute, $arguments, $section, $addQueryString, $argumentsToBeExcludedFromQueryString, $resolveShortcuts); $this->tag->addAttribute('href', $uri); } catch (NeosException $exception) { $this->systemLogger->logException($exception); } $linkedNode = $this->linkingService->getLastLinkedNode(); $this->templateVariableContainer->add($nodeVariableName, $linkedNode); $content = $this->renderChildren(); $this->templateVariableContainer->remove($nodeVariableName, $linkedNode); if ($content === NULL && $linkedNode !== NULL) { $content = $linkedNode->getLabel(); } $this->tag->setContent($content); $this->tag->forceClosingTag(TRUE); return $this->tag->render(); }
/** * Renders the link. Renders the linked node's label if there's no child content. * * @param mixed $node A node object or a string node path or NULL to resolve the current document node * @param string $format Format to use for the URL, for example "html" or "json" * @param boolean $absolute If set, an absolute URI is rendered * @param array $arguments Additional arguments to be passed to the UriBuilder (for example pagination parameters) * @param string $section The anchor to be added to the URI * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE * @param string $nodeVariableName The variable the node will be assigned to for the rendered child content * @param string $baseNodeName The name of the base node inside the TypoScript context to use for the ContentContext or resolving relative paths * @param boolean $resolveShortcuts INTERNAL Parameter - if FALSE, shortcuts are not redirected to their target. Only needed on rare backend occasions when we want to link to the shortcut itself. * @return string The rendered link * @throws ViewHelperException */ public function render($node = null, $format = null, $absolute = false, array $arguments = array(), $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $baseNodeName = 'documentNode', $nodeVariableName = 'linkedNode', $resolveShortcuts = true) { $baseNode = null; if (!$node instanceof NodeInterface) { $baseNode = $this->getContextVariable($baseNodeName); } try { $uri = $this->linkingService->createNodeUri($this->controllerContext, $node, $baseNode, $format, $absolute, $arguments, $section, $addQueryString, $argumentsToBeExcludedFromQueryString, $resolveShortcuts); $this->tag->addAttribute('href', $uri); } catch (NeosException $exception) { $this->systemLogger->logException($exception); } catch (NoMatchingRouteException $exception) { $this->systemLogger->logException($exception); } $linkedNode = $this->linkingService->getLastLinkedNode(); $this->templateVariableContainer->add($nodeVariableName, $linkedNode); $content = $this->renderChildren(); $this->templateVariableContainer->remove($nodeVariableName); if ($content === null && $linkedNode !== null) { $content = $linkedNode->getLabel(); } $this->tag->setContent($content); $this->tag->forceClosingTag(true); return $this->tag->render(); }