Skip to content

Commit

Permalink
Merge pull request #11 from Sebobo/task/neos-5-compatibility
Browse files Browse the repository at this point in the history
TASK: Neos 5 compatibility
  • Loading branch information
breadlesscode authored Mar 31, 2020
2 parents f80a1ce + b9ecf51 commit 2493e91
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[.html,.yml,.yaml]
[*.yaml]
indent_size = 2

[*.xlf]
Expand Down
58 changes: 39 additions & 19 deletions Classes/Package/FrontendNodeRoutePartHandler.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
<?php
declare(strict_types=1);

namespace Breadlesscode\NodeTypes\Folder\Package;

use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Exception\NodeException;
use Neos\Neos\Domain\Service\SiteService;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Neos\Routing\Exception;
use \Neos\Neos\Routing\FrontendNodeRoutePartHandler as NeosFrontendNodeRoutePartHandler;
use Neos\Neos\Routing\FrontendNodeRoutePartHandler as NeosFrontendNodeRoutePartHandler;

/**
* A route part handler for finding nodes specifically in the website's frontend.
*/
class FrontendNodeRoutePartHandler extends NeosFrontendNodeRoutePartHandler
{
/**
* folder mixin type for hiding uri segement
* Folder mixin property for hiding uri segment
*/
const MIXIN_PROPERTY_NAME = 'hideSegmentInUriPath';
public const MIXIN_PROPERTY_NAME = 'hideSegmentInUriPath';


/**
* @Flow\InjectConfiguration("routing.supportEmptySegmentForDimensions", package="Neos.Neos")
* @var boolean
*/
protected $supportEmptySegmentForDimensions;
protected bool $supportEmptySegmentForDimensions;

/**
* @param string $requestPath
* @return string
*/
protected function getWorkspaceName($requestPath)
protected function getWorkspaceName($requestPath): string
{
$contextPathParts = [];
if ($requestPath !== '' && strpos($requestPath, '@') !== false) {
Expand All @@ -40,8 +44,10 @@ protected function getWorkspaceName($requestPath)

return $contextPathParts['WorkspaceName'];
}

/**
* @inheritdoc
* @throws NodeException
*/
protected function getRelativeNodePathByUriPathSegmentProperties(NodeInterface $siteNode, $relativeRequestPath)
{
Expand All @@ -62,21 +68,23 @@ protected function getRelativeNodePathByUriPathSegmentProperties(NodeInterface $
}
return implode('/', $relativeNodePathSegments);
}

/**
* @param NodeInterface $startingNode
* @param string $pathSegment
* @param array $relativeNodePathSegments
* @param string $workspaceName
* @return NodeInterface
* @return NodeInterface|null
* @throws NodeException
*/
protected function findNextNodeWithPathSegmentRecursively(
protected function findNextNodeWithPathSegmentRecursively(
NodeInterface $startingNode,
$pathSegment,
&$relativeNodePathSegments,
$workspaceName
) {
): ?NodeInterface {
foreach ($startingNode->getChildNodes('Neos.Neos:Document') as $node) {
if ($workspaceName == 'live' && $this->shouldHideNodeUriSegement($node)) {
if ($workspaceName === 'live' && $this->shouldHideNodeUriSegment($node)) {
$foundNode = $this->findNextNodeWithPathSegmentRecursively(
$node,
$pathSegment,
Expand All @@ -95,10 +103,12 @@ protected function findNextNodeWithPathSegmentRecursively(
}
return null;
}

/**
* @inheritdoc
* @throws NodeException
*/
protected function getRequestPathByNode(NodeInterface $node)
protected function getRequestPathByNode(NodeInterface $node): string
{
if ($node->getParentPath() === SiteService::SITES_ROOT_PATH) {
return '';
Expand All @@ -110,36 +120,46 @@ protected function getRequestPathByNode(NodeInterface $node)
return parent::getRequestPathByNode($node);
}

// To allow building of paths to non-hidden nodes beneath hidden nodes, we assume
// the input node is allowed to be seen and we must generate the full path here.
// To disallow showing a node actually hidden itself has to be ensured in matching
// a request path, not in building one.
$contextProperties = $node->getContext()->getProperties();
$contextAllowingHiddenNodes = $this->contextFactory->create(array_merge($contextProperties, ['invisibleContentShown' => true]));
$currentNode = $contextAllowingHiddenNodes->getNodeByIdentifier($node->getIdentifier());

$requestPathSegments = [];
while ($node->getParentPath() !== SiteService::SITES_ROOT_PATH && $node instanceof NodeInterface) {
if (!$node->hasProperty('uriPathSegment')) {
while ($currentNode->getParentPath() !== SiteService::SITES_ROOT_PATH && $currentNode instanceof NodeInterface) {
if (!$currentNode->hasProperty('uriPathSegment')) {
throw new Exception\MissingNodePropertyException(
sprintf(
'Missing "uriPathSegment" property for node "%s". Nodes can be migrated with the "flow node:repair" command.',
$node->getPath()
$currentNode->getPath()
),
1415020326
);
}

if ($startingNode === $node || !$this->shouldHideNodeUriSegement($node)) {
$pathSegment = $node->getProperty('uriPathSegment');
if ($startingNode === $currentNode || !$this->shouldHideNodeUriSegment($currentNode)) {
$pathSegment = $currentNode->getProperty('uriPathSegment');
$requestPathSegments[] = $pathSegment;
}
$node = $node->getParent();
if ($node === null || !$node->isVisible()) {
$currentNode = $currentNode->getParent();
if ($currentNode === null || !$currentNode->isVisible()) {
return '';
}
}
return implode('/', array_reverse($requestPathSegments));
}

/**
* check for hiding uri segement of node
* Check for hiding uri segment of node
*
* @param NodeInterface $node
* @return boolean
* @throws NodeException
*/
protected function shouldHideNodeUriSegement(NodeInterface $node)
protected function shouldHideNodeUriSegment(NodeInterface $node): bool
{
return
$node->hasProperty(self::MIXIN_PROPERTY_NAME) &&
Expand Down
3 changes: 3 additions & 0 deletions Configuration/NodeTypes.Document.Folder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
ui:
label: 'i18n'
icon: 'folder'
properties:
_hiddenInIndex:
defaultValue: true

24 changes: 20 additions & 4 deletions Resources/Private/Fusion/Document/Folder.fusion
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
prototype(Breadlesscode.NodeTypes.Folder:Document.Folder) < prototype(Neos.Fusion:Tag) {
tagName = 'p'
content = ${ Translation.translate('Breadlesscode.NodeTypes.Folder:NodeTypes.Document.Folder:ui.label') }
[email protected] = ${ '<b>' + value + ':</b> ' + q(node).property('title') }
prototype(Breadlesscode.NodeTypes.Folder:Document.Folder) < prototype(Neos.Fusion:Case) {
backend {
condition = ${documentNode.context.inBackend}
renderer = Neos.Neos:Page {
body = Neos.Fusion:Tag {
tagName = 'p'
content = ${ Translation.translate('Breadlesscode.NodeTypes.Folder:NodeTypes.Document.Folder:ui.label') }
[email protected] = ${ '<b>' + value + ':</b> ' + q(node).property('title') }
}
}
}

default {
condition = true
renderer = Neos.Neos:Page {
body = Neos.Neos:Shortcut {
targetMode = 'parentNode'
}
}
}
}
15 changes: 1 addition & 14 deletions Resources/Private/Fusion/Root.fusion
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
include: Document/*.fusion

#
# Have fun by using this package
# If you see an issue please report it here:
# https://github.com/breadlesscode/neos-nodetypes-folder/issues
#

root.folder {
condition = ${ q(node).is('[instanceof Breadlesscode.NodeTypes.Folder:Document.Folder]') }
renderPath = '/folder'
}

folder = Breadlesscode.NodeTypes.Folder:Document.Folder
include: **/*
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "breadlesscode/neos-nodetypes-folder",
"license": "MIT",
"require": {
"neos/neos": "~3.0 || ~4.0"
"neos/neos": "~4.3 || ~5.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 2493e91

Please sign in to comment.