Skip to content

Commit

Permalink
TASK: WIP Adjust to Flow Controller changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Nov 11, 2023
1 parent dcc9174 commit 8936fc4
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Neos.Neos/Classes/Controller/Backend/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ public function indexAction(array $module)

$moduleRequest->setArgument('__moduleConfiguration', $moduleConfiguration);

$moduleResponse = new ActionResponse();

$this->dispatcher->dispatch($moduleRequest, $moduleResponse);
$moduleResponse = $this->dispatcher->dispatch($moduleRequest);

if ($moduleResponse->getRedirectUri() !== null) {
$this->redirectToUri($moduleResponse->getRedirectUri(), 0, $moduleResponse->getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ final class SiteDetectionMiddleware implements MiddlewareInterface

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// return $handler->handle($siteDetectionResult->storeInRequest($request));
$requestUriHost = $request->getUri()->getHost();
$site = null;
if (!empty($requestUriHost)) {
Expand Down
3 changes: 1 addition & 2 deletions Neos.Neos/Classes/Fusion/PluginImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ public function evaluate(): string
$this->node = $currentContext['node'];
$this->documentNode = $currentContext['documentNode'];
$parentResponse = $this->runtime->getControllerContext()->getResponse();
$pluginResponse = new ActionResponse();
$this->dispatcher->dispatch($this->buildPluginRequest(), $pluginResponse);
$pluginResponse = $this->dispatcher->dispatch($this->buildPluginRequest());

// We need to make sure to not merge content up into the parent ActionResponse
// because that would break the Fusion HttpResponse.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,23 @@ public function errorAction(): never
* TODO: This is an explicit exception handling that will be replaced by format-enabled exception handlers.
*
* @param ActionRequest $request The request object
* @param ActionResponse $response The response, modified by this handler
* @return void
* @return ActionResponse $response The response, modified by this handler
* @throws StopActionException
* @throws \Exception
*/
public function processRequest(ActionRequest $request, ActionResponse $response)
public function processRequest(ActionRequest $request): ActionResponse
{
$response = new ActionResponse();
try {
parent::processRequest($request, $response);
$response = parent::processRequest($request);
} catch (StopActionException $exception) {
throw $exception;
} catch (\Exception $exception) {
if ($this->request->getFormat() !== 'json') {
throw $exception;
}
$exceptionData = $this->convertException($exception);
$response = new ActionResponse();
$response->setContentType('application/json');
if ($exception instanceof FlowException) {
$response->setStatusCode($exception->getStatusCode());
Expand All @@ -114,6 +115,8 @@ public function processRequest(ActionRequest $request, ActionResponse $response)
LogEnvironment::fromMethodName(__METHOD__)
);
}

return $response;
}

/**
Expand Down
26 changes: 19 additions & 7 deletions Neos.Neos/Classes/Service/Controller/UserPreferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,37 @@

namespace Neos\Neos\Service\Controller;

use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Annotations as Flow;

use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\SimpleActionController;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Domain\Service\UserService;

/**
* Service Controller for user preferences
*/
class UserPreferenceController extends AbstractServiceController
class UserPreferenceController extends SimpleActionController
{
#[Flow\Inject]
protected UserService $domainUserService;

/**
* @return string json encoded user preferences
* @return ActionResponse json encoded user preferences
*/
public function indexAction(): string
public function indexAction(ActionRequest $request): ActionResponse
{
$this->response->setContentType('application/json');

return json_encode(
$response = new ActionResponse();
$response->setContentType('application/json');
$response->setContent(json_encode(
$this->domainUserService->getCurrentUser()?->getPreferences()->getPreferences(),
JSON_THROW_ON_ERROR
);
));

return $response;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions Neos.Neos/Configuration/Routes.Service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
'@format': 'json'
httpMethods: ['GET']

- name: 'Services - UserPreferencesController->redirect'
uriPattern: 'user-preferences-redir'
defaults:
'@package': 'Neos.Neos'
'@subpackage': 'Service'
'@controller': 'UserPreference'
'@action': 'redirect'
'@format': 'html'
httpMethods: [ 'GET' ]


-
name: 'Services - UserPreferencesController->update'
uriPattern: 'user-preferences'
Expand Down

0 comments on commit 8936fc4

Please sign in to comment.