Skip to content

Commit

Permalink
Merge pull request #4505 from neos/90/editPreviewModeSupport_v3
Browse files Browse the repository at this point in the history
!!! FEATURE: Reimplement EditPreviewModes for Neos 9
  • Loading branch information
mficzel authored Sep 16, 2023
2 parents 56aef70 + 3202c4e commit 96e4257
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 327 deletions.
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

0 comments on commit 96e4257

Please sign in to comment.