Skip to content

Commit

Permalink
Merge pull request #4874 from mhsdesign/task/renderingModeFollowup
Browse files Browse the repository at this point in the history
TASK: Use `renderingMode.isEdit` in `NodeController`
  • Loading branch information
mhsdesign authored Feb 7, 2024
2 parents 86582ef + 48aeebf commit 10fbb8b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
15 changes: 8 additions & 7 deletions Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;
use Neos\Neos\View\FusionView;

/**
* Event Sourced Node Controller; as Replacement of NodeController
*/
class NodeController extends ActionController
{
use NodeTypeWithFallbackProvider;
Expand Down Expand Up @@ -110,7 +107,7 @@ class NodeController extends ActionController
protected int $shortcutRedirectHttpStatusCode;

/**
* @param string $node Legacy name for backwards compatibility of route components
* @param string $node
* @throws NodeNotFoundException
* @throws \Neos\Flow\Mvc\Exception\StopActionException
* @throws \Neos\Flow\Mvc\Routing\Exception\MissingActionNameException
Expand Down Expand Up @@ -157,7 +154,11 @@ public function previewAction(string $node): void
);
}

if ($this->getNodeType($nodeInstance)->isOfType(NodeTypeNameFactory::NAME_SHORTCUT) && $nodeAddress->isInLiveWorkspace()) {
if (
$this->getNodeType($nodeInstance)->isOfType(NodeTypeNameFactory::NAME_SHORTCUT)
&& !$renderingMode->isEdit
&& $nodeAddress->workspaceName->isLive() // shortcuts are only resolvable for the live workspace
) {
$this->handleShortcutNode($nodeAddress, $contentRepository);
}

Expand All @@ -168,7 +169,7 @@ public function previewAction(string $node): void
'site' => $site,
]);

if (!$nodeAddress->isInLiveWorkspace()) {
if ($renderingMode->isEdit) {
$this->overrideViewVariablesFromInternalArguments();
$this->response->setHttpHeader('Cache-Control', 'no-cache');
if (!$this->view->canRenderWithNodeAndPath()) {
Expand Down Expand Up @@ -266,7 +267,7 @@ protected function overrideViewVariablesFromInternalArguments()
}

/**
* Handles redirects to shortcut targets in live rendering.
* Handles redirects to shortcut targets of nodes in the live workspace.
*
* @param NodeAddress $nodeAddress
* @throws NodeNotFoundException
Expand Down
9 changes: 4 additions & 5 deletions Neos.Neos/Classes/Domain/Model/RenderingMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
* Describes the mode in which the Neos interface is rendering currently,
* mainly distinguishing between edit and preview modes currently.
*/
class RenderingMode
final class RenderingMode
{
public const FRONTEND = 'frontend';

/**
* @param array<string,mixed> $options
*/
public function __construct(
private function __construct(
public readonly string $name,
public readonly bool $isEdit,
public readonly bool $isPreview,
Expand All @@ -52,23 +52,22 @@ public static function createFromConfiguration(string $modeName, array $configur
1694802951840
);
}
$mode = new RenderingMode(
return new self(
$modeName,
$configuration['isEditingMode'] ?? false,
$configuration['isPreviewMode'] ?? false,
$configuration['title'] ?? $modeName,
$configuration['fusionRenderingPath'] ?? '',
$configuration['options'] ?? [],
);
return $mode;
}

/**
* Creates the system integrated rendering mode 'frontend'
*/
public static function createFrontend(): RenderingMode
{
return new RenderingMode(
return new self(
RenderingMode::FRONTEND,
false,
false,
Expand Down
3 changes: 3 additions & 0 deletions Neos.Neos/Classes/FrontendRouting/NodeShortcutResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public function __construct(
*/
public function resolveShortcutTarget(NodeAddress $nodeAddress, ContentRepository $contentRepository)
{
if (!$nodeAddress->workspaceName->isLive()) {
throw new \RuntimeException(sprintf('Cannot resolve shortcut target for node-address %s in workspace %s because the DocumentUriPathProjection only handles the live workspace.', $nodeAddress->nodeAggregateId->value, $nodeAddress->workspaceName->value), 1707208650);
}
$documentUriPathFinder = $contentRepository->projectionState(DocumentUriPathFinder::class);
$documentNodeInfo = $documentUriPathFinder->getByIdAndDimensionSpacePointHash(
$nodeAddress->nodeAggregateId,
Expand Down
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 10fbb8b

Please sign in to comment.