Neos\Neos\Domain\Service\NodeShortcutResolver::resolveShortcutTarget PHP Method

resolveShortcutTarget() public method

* a NodeInterface instance if the target is a node or a node:// URI * a string (in case the target is a plain text URI or an asset:// URI) * NULL in case the shortcut cannot be resolved
public resolveShortcutTarget ( Neos\ContentRepository\Domain\Model\NodeInterface $node ) : Neos\ContentRepository\Domain\Model\NodeInterface | string | null
$node Neos\ContentRepository\Domain\Model\NodeInterface
return Neos\ContentRepository\Domain\Model\NodeInterface | string | null
    public function resolveShortcutTarget(NodeInterface $node)
    {
        $infiniteLoopPrevention = 0;
        while ($node->getNodeType()->isOfType('Neos.Neos:Shortcut') && $infiniteLoopPrevention < 50) {
            $infiniteLoopPrevention++;
            switch ($node->getProperty('targetMode')) {
                case 'selectedTarget':
                    $target = $node->getProperty('target');
                    if ($this->linkingService->hasSupportedScheme($target)) {
                        $targetObject = $this->linkingService->convertUriToObject($target, $node);
                        if ($targetObject instanceof NodeInterface) {
                            $node = $targetObject;
                        } elseif ($targetObject instanceof AssetInterface) {
                            return $this->linkingService->resolveAssetUri($target);
                        }
                    } else {
                        return $target;
                    }
                    break;
                case 'parentNode':
                    $node = $node->getParent();
                    break;
                case 'firstChildNode':
                default:
                    $childNodes = $node->getChildNodes('Neos.Neos:Document');
                    if ($childNodes !== array()) {
                        $node = reset($childNodes);
                    } else {
                        return null;
                    }
            }
        }
        return $node;
    }

Usage Example

Example #1
0
 /**
  * Handles redirects to shortcut targets in live rendering.
  *
  * @param NodeInterface $node
  * @return void
  * @throws NodeNotFoundException|UnresolvableShortcutException
  */
 protected function handleShortcutNode(NodeInterface $node)
 {
     $resolvedNode = $this->nodeShortcutResolver->resolveShortcutTarget($node);
     if ($resolvedNode === null) {
         throw new NodeNotFoundException(sprintf('The shortcut node target of node "%s" could not be resolved', $node->getPath()), 1430218730);
     } elseif (is_string($resolvedNode)) {
         $this->redirectToUri($resolvedNode);
     } elseif ($resolvedNode instanceof NodeInterface) {
         $this->redirect('show', null, null, ['node' => $resolvedNode]);
     } else {
         throw new UnresolvableShortcutException(sprintf('The shortcut node target of node "%s" resolves to an unsupported type "%s"', $node->getPath(), is_object($resolvedNode) ? get_class($resolvedNode) : gettype($resolvedNode)), 1430218738);
     }
 }
All Usage Examples Of Neos\Neos\Domain\Service\NodeShortcutResolver::resolveShortcutTarget
NodeShortcutResolver