Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Adjust to Flow Controller changes #4738

Merged
merged 14 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
$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' ]
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved


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