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 all commits
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
12 changes: 12 additions & 0 deletions Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
use Neos\Flow\Security\Context as SecurityContext;
use Neos\Flow\Session\SessionInterface;
use Neos\Flow\Utility\Now;
use Neos\Neos\Domain\Model\RenderingMode;
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,6 +110,9 @@ class NodeController extends ActionController
*/
protected $nodeSiteResolvingService;

#[Flow\Inject]
protected RenderingModeService $renderingModeService;

/**
* @param string $node Legacy name for backwards compatibility of route components
* @throws NodeNotFoundException
Expand All @@ -122,6 +127,9 @@ class NodeController extends ActionController
*/
public function previewAction(string $node): void
{
// @todo add $renderingModeName as parameter and append it for successive links again as get parameter to node uris
$renderingMode = $this->renderingModeService->findByCurrentUser();

$visibilityConstraints = VisibilityConstraints::frontend();
if ($this->privilegeManager->isPrivilegeTargetGranted('Neos.Neos:Backend.GeneralAccess')) {
$visibilityConstraints = VisibilityConstraints::withoutRestrictions();
Expand Down Expand Up @@ -161,6 +169,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 +244,8 @@ public function showAction(string $node, bool $showInvisible = false): void
$this->handleShortcutNode($nodeAddress, $contentRepository);
}

$this->view->setOption('renderingModeName', RenderingMode::FRONTEND);

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

/**
* Describes the mode in which the Neos interface is rendering currently,
* mainly distinguishing between edit and preview modes currently.
*/
class RenderingMode
{
public const FRONTEND = 'frontend';

/**
* @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 a rendering mode from its configuration
*
* @param string $modeName
* @param array<string,mixed> $configuration
*/
public static function createFromConfiguration(string $modeName, array $configuration): RenderingMode
{
if ($modeName === RenderingMode::FRONTEND) {
throw new Exception(
'Cannot instantiate system rendering mode "frontend" from configuration.'
. ' Please use RenderingMode::createFrontend().',
1694802951840
);
}
$mode = new RenderingMode(
$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(
RenderingMode::FRONTEND,
false,
false,
'Frontend',
'',
[]
);
}
}
187 changes: 0 additions & 187 deletions Neos.Neos/Classes/Domain/Model/UserInterfaceMode.php

This file was deleted.

Loading
Loading