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

!!! FEATURE: Reimplement EditPreviewModes for Neos 9 #4505

Merged
merged 6 commits into from
Sep 16, 2023
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
17 changes: 16 additions & 1 deletion Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Neos\Flow\Session\SessionInterface;
use Neos\Flow\Utility\Now;
use Neos\Neos\Domain\Service\NodeSiteResolvingService;
use Neos\Neos\Domain\Service\RenderingModeService;
use Neos\Neos\FrontendRouting\Exception\InvalidShortcutException;
use Neos\Neos\FrontendRouting\Exception\NodeNotFoundException;
use Neos\Neos\FrontendRouting\NodeAddress;
Expand Down Expand Up @@ -108,8 +109,12 @@ class NodeController extends ActionController
*/
protected $nodeSiteResolvingService;

#[Flow\Inject]
protected RenderingModeService $renderingModeService;

/**
* @param string $node Legacy name for backwards compatibility of route components
* @param string $renderingModeName Name of the user interface mode to use
* @throws NodeNotFoundException
* @throws \Neos\Flow\Mvc\Exception\StopActionException
* @throws \Neos\Flow\Mvc\Exception\UnsupportedRequestTypeException
Expand All @@ -120,8 +125,14 @@ class NodeController extends ActionController
* with unsafe requests from widgets or plugins that are rendered on the node
* - For those the CSRF token is validated on the sub-request, so it is safe to be skipped here
*/
public function previewAction(string $node): void
public function previewAction(string $node, string $renderingModeName = null): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the ui will currently not use this parameter yet (it could via neos/neos-ui#3411)

But importantly this change allows us to open a page in a new tab independent of the session's value.
Although this would only work for this one page, successive links will currently not have that query param added - the linking service still needs to lear this, but this is out of scope of this pr.

{
if (is_null($renderingModeName)) {
$renderingMode = $this->renderingModeService->findByCurrentUser();
} else {
$renderingMode = $this->renderingModeService->findByName($renderingModeName);
}

$visibilityConstraints = VisibilityConstraints::frontend();
if ($this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
$visibilityConstraints = VisibilityConstraints::withoutRestrictions();
Expand Down Expand Up @@ -161,6 +172,8 @@ public function previewAction(string $node): void
$this->handleShortcutNode($nodeAddress, $contentRepository);
}

$this->view->setOption('renderingModeName', $renderingMode->name);

$this->view->assignMultiple([
'value' => $nodeInstance,
'site' => $site,
Expand Down Expand Up @@ -234,6 +247,8 @@ public function showAction(string $node, bool $showInvisible = false): void
$this->handleShortcutNode($nodeAddress, $contentRepository);
}

$this->view->setOption('renderingModeName', 'frontend');

$this->view->assignMultiple([
'value' => $nodeInstance,
'site' => $site,
Expand Down
71 changes: 71 additions & 0 deletions Neos.Neos/Classes/Domain/Model/RenderingMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the Neos.Neos package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

declare(strict_types=1);

namespace Neos\Neos\Domain\Model;

use Neos\Utility\ObjectAccess;

/**
* Describes the mode in which the Neos interface is rendering currently,
* mainly distinguishing between edit and preview modes currently.
*/
class RenderingMode
{
/**
* @param array<string,mixed> $options
*/
public function __construct(
public readonly string $name,
public readonly bool $isEdit,
public readonly bool $isPreview,
public readonly string $title,
public readonly string $fusionPath,
public readonly array $options
) {
}

/**
* Creates an UserInterfaceMode object by configuration
*
* @param string $modeName
* @param array<string,mixed> $configuration
*/
public static function createFromConfiguration(string $modeName, array $configuration): RenderingMode
{
$mode = new RenderingMode(
$modeName,
$configuration['isEditingMode'] ?? false,
$configuration['isPreviewMode'] ?? false,
$configuration['title'] ?? $modeName,
$configuration['fusionRenderingPath'] ?? '',
$configuration['options'] ?? [],
);
return $mode;
}

/**
* Creates the live User interface mode
*/
public static function createFrontend(): RenderingMode
{
return new RenderingMode(
'frontend',
false,
false,
'Frontend',
'',
[]
);
}
}
187 changes: 0 additions & 187 deletions Neos.Neos/Classes/Domain/Model/UserInterfaceMode.php

This file was deleted.

Loading