Skip to content

Commit

Permalink
WIP: Linking Service action implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pKallert committed Apr 29, 2023
1 parent 336c1c7 commit 125b35e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function initializeEditAction(): void
}

/**
* Previews a node that is not live (i.e. for the Backend Preview & Edit Mode)
* Previews a node that is not live (i.e. for the Backend Preview Mode)
*
* @param NodeInterface $node
* @return string View output for the specified node
Expand Down Expand Up @@ -161,6 +161,15 @@ public function previewAction(NodeInterface $node = null)
}
}

/**
* Renders a node in backend
*
* @param NodeInterface|null $node
* @throws NeosException
* @throws NodeNotFoundException
* @throws SessionNotStartedException
* @throws UnresolvableShortcutException
*/
public function editAction(NodeInterface $node = null)
{
if ($node === null) {
Expand All @@ -181,6 +190,7 @@ public function editAction(NodeInterface $node = null)
if (!$this->view->canRenderWithNodeAndPath()) {
$this->view->setFusionPath('rawContent');
}

if ($this->session->isStarted()) {
$this->session->putData('lastVisitedNode', $node->getContextPath());
}
Expand Down
26 changes: 24 additions & 2 deletions Neos.Neos/Classes/Service/LinkingService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Neos\Neos\Service;

/*
Expand All @@ -11,6 +12,7 @@
* source code.
*/

use http\Exception\RuntimeException;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\BaseUriProvider;
Expand All @@ -29,6 +31,7 @@
use Neos\Neos\TYPO3CR\NeosNodeServiceInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerInterface;
use function Psalm\get_path_to_config;

/**
* A service for creating URIs pointing to nodes and assets.
Expand Down Expand Up @@ -242,7 +245,7 @@ public function convertUriToObject($uri, NodeInterface $contextNode = null)
* @throws HttpException
* @throws \Neos\Flow\Persistence\Exception\IllegalObjectTypeException
*/
public function createNodeUri(ControllerContext $controllerContext, $node = null, NodeInterface $baseNode = null, $format = null, $absolute = false, array $arguments = [], $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $resolveShortcuts = true): string
public function createNodeUri(ControllerContext $controllerContext, $node = null, NodeInterface $baseNode = null, $format = null, $absolute = false, array $arguments = [], $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $resolveShortcuts = true, ?string $overrideDefaultAction = null): string
{
$this->lastLinkedNode = null;
if ($resolveShortcuts === false) {
Expand Down Expand Up @@ -284,7 +287,7 @@ public function createNodeUri(ControllerContext $controllerContext, $node = null
$request = $controllerContext->getRequest()->getMainRequest();
$uriBuilder = clone $controllerContext->getUriBuilder();
$uriBuilder->setRequest($request);
$action = $node->getContext()->getWorkspace()->isPublicWorkspace() && !$node->isHidden() ? 'show' : 'edit';
$action = $this->determineAction($request, $overrideDefaultAction);
return $uriBuilder
->reset()
->setSection($section)
Expand Down Expand Up @@ -333,4 +336,23 @@ public function getLastLinkedNode(): ?NodeInterface
{
return $this->lastLinkedNode;
}

/**
* @param NodeInterface $node
* @param \Neos\Flow\Mvc\ActionRequest $request
* @return string
* @throws \Neos\Flow\Persistence\Exception\IllegalObjectTypeException
*/
private function determineAction(\Neos\Flow\Mvc\ActionRequest $request, ?string $overrideActionName): string
{
$validActions = ['show', 'preview', 'edit'];
if ($overrideActionName === null) {
return in_array($request->getControllerActionName(), $validActions) ? $request->getControllerActionName() : 'show';
}
if (in_array($overrideActionName, $validActions)) {
return $overrideActionName;
}
throw new \RuntimeException('Override action not allowed', 1682778247);

}
}

0 comments on commit 125b35e

Please sign in to comment.