Neos\Neos\ViewHelpers\Link\NodeViewHelper::render PHP Метод

render() публичный Метод

Renders the link. Renders the linked node's label if there's no child content.
public render ( mixed $node = null, string $format = null, boolean $absolute = false, array $arguments = [], string $section = '', boolean $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], string $baseNodeName = 'documentNode', string $nodeVariableName = 'linkedNode', boolean $resolveShortcuts = true ) : string
$node mixed A node object, a string node path (absolute or relative), a string node://-uri or NULL
$format string Format to use for the URL, for example "html" or "json"
$absolute boolean If set, an absolute URI is rendered
$arguments array Additional arguments to be passed to the UriBuilder (for example pagination parameters)
$section string The anchor to be added to the URI
$addQueryString boolean If set, the current query parameters will be kept in the URI
$argumentsToBeExcludedFromQueryString array arguments to be removed from the URI. Only active if $addQueryString = TRUE
$baseNodeName string The name of the base node inside the TypoScript context to use for the ContentContext or resolving relative paths
$nodeVariableName string The variable the node will be assigned to for the rendered child content
$resolveShortcuts boolean 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.
Результат string The rendered link
    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);
            if (is_string($node) && substr($node, 0, 7) === 'node://') {
                $node = $this->linkingService->convertUriToObject($node, $baseNode);
            }
        }
        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();
    }

Usage Example

 /**
  * @test
  */
 public function viewHelperAssignsLinkedNodeToNodeVariableName()
 {
     $templateVariableContainer = new TemplateVariableContainer(array());
     $this->inject($this->viewHelper, 'templateVariableContainer', $templateVariableContainer);
     $this->viewHelper->setRenderChildrenClosure(function () use($templateVariableContainer) {
         return $templateVariableContainer->get('alternativeLinkedNode')->getLabel();
     });
     $this->assertSame('<a href="/en/home.html">Home</a>', $this->viewHelper->render('/sites/example/home@live', null, false, array(), '', false, array(), 'documentNode', 'alternativeLinkedNode'));
 }