Skip to content

Commit

Permalink
WIP REVERT ME!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 15, 2024
1 parent b1dabad commit 0b311df
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 15 deletions.
72 changes: 65 additions & 7 deletions Neos.Neos/Classes/Fusion/NodeUriImplementation.php
Expand Up @@ -18,11 +18,18 @@
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\Arguments;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Mvc\Exception\NoMatchingRouteException;
use Neos\Flow\Mvc\Routing\UriBuilder;
use Neos\Fusion\Exception;
use Neos\Fusion\FusionObjects\AbstractFusionObject;
use Neos\Neos\Exception as NeosException;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\FrontendRouting\NodeUriBuilder;
use Neos\Neos\Service\LinkingService;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -42,6 +49,12 @@ class NodeUriImplementation extends AbstractFusionObject
*/
protected $systemLogger;

/**
* @Flow\Inject
* @var LinkingService
*/
protected $linkingService;

/**
* A node object or a string node path or NULL to resolve the current document node
*/
Expand Down Expand Up @@ -120,13 +133,8 @@ public function getBaseNodeName()
return $this->fusionValue('baseNodeName');
}

/**
* Render the Uri.
*
* @return string The rendered URI or NULL if no URI could be resolved for the given node
* @throws \Neos\Flow\Mvc\Routing\Exception\MissingActionNameException
*/
public function evaluate()

public function evaluate2()

Check failure on line 137 in Neos.Neos/Classes/Fusion/NodeUriImplementation.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test linting-unit-functionaltests-mysql (deps: highest)

Method Neos\Neos\Fusion\NodeUriImplementation::evaluate2() has no return type specified.

Check failure on line 137 in Neos.Neos/Classes/Fusion/NodeUriImplementation.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test linting-unit-functionaltests-mysql (deps: highest)

Method Neos\Neos\Fusion\NodeUriImplementation::evaluate2() has no return type specified.
{
$baseNode = null;
$baseNodeName = $this->getBaseNodeName() ?: 'documentNode';
Expand Down Expand Up @@ -175,4 +183,54 @@ public function evaluate()
}
return '';
}

/**
* Render the Uri.
*
* @return string The rendered URI or NULL if no URI could be resolved for the given node
*/
public function evaluate()
{
$baseNode = null;
$baseNodeName = $this->getBaseNodeName() ?: 'documentNode';
$currentContext = $this->runtime->getCurrentContext();
if (isset($currentContext[$baseNodeName])) {
$baseNode = $currentContext[$baseNodeName];
} else {
throw new NeosException(sprintf('Could not find a node instance in Fusion context with name "%s" and no node instance was given to the node argument. Set a node instance in the Fusion context or pass a node object to resolve the URI.', $baseNodeName), 1373100400);
}

$actionRequest = $this->getRuntime()->fusionGlobals->get('request');
if (!$actionRequest instanceof ActionRequest) {
throw new \Neos\Flow\Exception('The request is expected to be an ActionRequest.', 1707728033);
}

$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($actionRequest);

$fakeControllerContext = new ControllerContext(
$actionRequest,
new ActionResponse(),
new Arguments(),
$uriBuilder
);

$node = $this->getNode();
try {
return $this->linkingService->createNodeUri(
$fakeControllerContext,
$node,
$baseNode,
$this->getFormat(),
$this->isAbsolute(),
$this->getAdditionalParams(),
$this->getSection(),
$this->getAddQueryString(),
$this->getArgumentsToBeExcludedFromQueryString()
);
} catch (NoMatchingRouteException) {
$this->systemLogger->warning(sprintf('Could not resolve "%s" to a node uri. Arguments: %s', $node instanceof Node ? $node->nodeAggregateId->value : $node, json_encode($uriBuilder->getLastArguments())), LogEnvironment::fromMethodName(__METHOD__));
return '';
}
}
}
15 changes: 9 additions & 6 deletions Neos.Neos/Classes/Service/LinkingService.php
Expand Up @@ -14,6 +14,7 @@

namespace Neos\Neos\Service;

use Neos\ContentRepository\Core\Projection\ContentGraph\AbsoluteNodePath;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\NodeHiddenState\NodeHiddenStateFinder;
use Neos\ContentRepository\Core\Projection\NodeHiddenState\NodeHiddenStateProjection;
Expand Down Expand Up @@ -45,7 +46,9 @@
* The target node can be provided as string or as a Node object; if not specified
* at all, the generated URI will refer to the current document node inside the Fusion context.
*
* When specifying the ``node`` argument as string, the following conventions apply:
* When specifying the `node` argument as string, the following conventions apply:
*
*
*
* *``node`` starts with ``/``:*
* The given path is an absolute node path and is treated as such.
Expand All @@ -55,8 +58,6 @@
* The given path is treated as a path relative to the current node.
* Examples: given that the current node is ``/sites/acmecom/products/``,
* ``stapler`` results in ``/sites/acmecom/products/stapler``,
* ``../about`` results in ``/sites/acmecom/about/``,
* ``./neos/info`` results in ``/sites/acmecom/products/neos/info``.
*
* *``node`` starts with a tilde character (``~``):*
* The given path is treated as a path relative to the current site node.
Expand All @@ -70,6 +71,7 @@ class LinkingService
{
/**
* Pattern to match supported URIs.
* Todo doestn work with other node ids ....
*
* @var string
*/
Expand Down Expand Up @@ -246,8 +248,8 @@ public function convertUriToObject($uri, Node $contextNode = null)
* Renders the URI to a given node instance or -path.
*
* @param ControllerContext $controllerContext
* @param mixed $node A node object or a string node path,
* if a relative path is provided the baseNode argument is required
* @param Node|AbsoluteNodePath|string $node A node object or a string node path,
* if a relative path is provided the baseNode argument is required
* @param Node $baseNode
* @param string $format Format to use for the URL, for example "html" or "json"
* @param boolean $absolute If set, an absolute URI is rendered
Expand All @@ -267,7 +269,7 @@ public function convertUriToObject($uri, Node $contextNode = null)
*/
public function createNodeUri(
ControllerContext $controllerContext,
$node = null,
Node|string|AbsoluteNodePath $node = null,
Node $baseNode = null,
$format = null,
$absolute = false,
Expand Down Expand Up @@ -350,6 +352,7 @@ public function createNodeUri(
$request = $controllerContext->getRequest()->getMainRequest();
$uriBuilder = clone $controllerContext->getUriBuilder();
$uriBuilder->setRequest($request);
// hiddne good one .
$action = $workspace && $workspace->isPublicWorkspace() && !$hiddenState->isHidden ? 'show' : 'preview';

return $uriBuilder
Expand Down
9 changes: 7 additions & 2 deletions Neos.Neos/Classes/ViewHelpers/Uri/NodeViewHelper.php
Expand Up @@ -33,6 +33,7 @@
use Neos\FluidAdaptor\Core\ViewHelper\Exception as ViewHelperException;
use Neos\Fusion\ViewHelpers\FusionContextTrait;
use Neos\Neos\FrontendRouting\NodeUriBuilder;
use Neos\Neos\Utility\LegacyNodePathNormalizer;

/**
* A view helper for creating URIs pointing to nodes.
Expand All @@ -50,8 +51,6 @@
* The given path is treated as a path relative to the current node.
* Examples: given that the current node is ``/sites/acmecom/products/``,
* ``stapler`` results in ``/sites/acmecom/products/stapler``,
* ``../about`` results in ``/sites/acmecom/about/``,
* ``./neos/info`` results in ``/sites/acmecom/products/neos/info``.
*
* *``node`` starts with a tilde character (``~``):*
* The given path is treated as a path relative to the current site node.
Expand Down Expand Up @@ -112,6 +111,12 @@ class NodeViewHelper extends AbstractViewHelper
*/
protected $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var LegacyNodePathNormalizer
*/
protected $legacyNodePathNormalizer;

/**
* @Flow\Inject
* @var ThrowableStorageInterface
Expand Down

0 comments on commit 0b311df

Please sign in to comment.