Skip to content

Commit

Permalink
TASK: Document NodeUriBuilder::uriFor
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 6, 2024
1 parent e3ff7a4 commit 48aeebf
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Neos.Neos/Classes/FrontendRouting/NodeUriBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,30 @@ final class NodeUriBuilder
{
private UriBuilder $uriBuilder;

protected function __construct(UriBuilder $uriBuilder)
private function __construct(UriBuilder $uriBuilder)
{
$this->uriBuilder = $uriBuilder;
}

public static function fromRequest(ActionRequest $request): static
public static function fromRequest(ActionRequest $request): self
{
$uriBuilder = new UriBuilder();
$uriBuilder->setRequest($request);

return new static($uriBuilder);
return new self($uriBuilder);
}

public static function fromUriBuilder(UriBuilder $uriBuilder): static
public static function fromUriBuilder(UriBuilder $uriBuilder): self
{
return new static($uriBuilder);
return new self($uriBuilder);
}

/**
* Renders an URI for the given $nodeAddress
* If the node belongs to the live workspace, the public URL is generated
* Otherwise a preview URI is rendered (@see previewUriFor())
*
* Note: Shortcut nodes will are resolved in the RoutePartHandler thus the resulting URI will point
* Note: Shortcut nodes will be resolved in the RoutePartHandler thus the resulting URI will point
* to the shortcut target (node, asset or external URI)
*
* @param NodeAddress $nodeAddress
Expand All @@ -63,10 +63,11 @@ public static function fromUriBuilder(UriBuilder $uriBuilder): static
*/
public function uriFor(NodeAddress $nodeAddress): UriInterface
{
if (!$nodeAddress->isInLiveWorkspace()) {
if (!$nodeAddress->workspaceName->isLive()) {
// we cannot build a human-readable uri using the showAction as
// the DocumentUriPathProjection only handles the live workspace
return $this->previewUriFor($nodeAddress);
}
/** @noinspection PhpUnhandledExceptionInspection */
return new Uri($this->uriBuilder->uriFor('show', ['node' => $nodeAddress], 'Frontend\Node', 'Neos.Neos'));
}

Expand Down

0 comments on commit 48aeebf

Please sign in to comment.