Skip to content

Commit

Permalink
WIP: Re introduce hacky node converters, to be removed via neos#4873
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Feb 11, 2024
1 parent 6a9478a commit 2a2d068
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

declare(strict_types=1);

namespace Neos\Neos\TypeConverter;

/*
* This file is part of the Neos.ContentRepository 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.
*/

use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Http\RequestHandler;
use Neos\Flow\Property\PropertyMappingConfigurationInterface;
use Neos\Flow\Property\TypeConverter\AbstractTypeConverter;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult;

/**
* To be removed legacy fragment for property mapping nodes in controllers.
* MUST not be used and MUST be removed before Neos 9 release.
* See issue: https://github.com/neos/neos-development-collection/issues/4873
*
* @Flow\Scope("singleton")
* @deprecated must be removed before Neos 9 release!!!
*/
class HackyNodeAddressToNodeConverter extends AbstractTypeConverter
{
/**
* @var array<int,string>
*/
protected $sourceTypes = ['string'];

/**
* @var string
*/
protected $targetType = Node::class;

/**
* @var integer
*/
protected $priority = 2;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;
#[Flow\Inject]
protected Bootstrap $bootstrap;

/**
* @param string $source
* @param string $targetType
* @param array<string,string> $subProperties
* @return ?Node
*/
public function convertFrom(
$source,
$targetType = null,
array $subProperties = [],
PropertyMappingConfigurationInterface $configuration = null
) {
$activeRequestHandler = $this->bootstrap->getActiveRequestHandler();
$contentRepositoryId = ContentRepositoryId::fromString('default');
if ($activeRequestHandler instanceof RequestHandler) {
$httpRequest = $activeRequestHandler->getHttpRequest();
$siteDetectionResult = SiteDetectionResult::fromRequest($httpRequest);
$contentRepositoryId = $siteDetectionResult->contentRepositoryId;
}

$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$nodeAddressFactory = NodeAddressFactory::create($contentRepository);
$nodeAddress = $nodeAddressFactory->createFromUriString($source);

$subgraph = $contentRepository->getContentGraph()
->getSubgraph(
$nodeAddress->contentStreamId,
$nodeAddress->dimensionSpacePoint,
$nodeAddress->isInLiveWorkspace()
? VisibilityConstraints::frontend()
: VisibilityConstraints::withoutRestrictions()
);

return $subgraph->findNodeById($nodeAddress->nodeAggregateId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

/*
* This file is part of the Neos.ContentRepository 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\TypeConverter;

use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Property\PropertyMappingConfigurationInterface;
use Neos\Flow\Property\TypeConverter\AbstractTypeConverter;

/**
* To be removed legacy fragment for property mapping nodes in controllers.
* MUST not be used and MUST be removed before Neos 9 release.
* See issue: https://github.com/neos/neos-development-collection/issues/4873
*
* @Flow\Scope("singleton")
* @deprecated must be removed before Neos 9 release!!!
*/
class NodeToNodeAddressStringConverter extends AbstractTypeConverter
{
/**
* @Flow\Inject
* @var ContentRepositoryRegistry
*/
protected $contentRepositoryRegistry;

/**
* @var array<int,string>
*/
protected $sourceTypes = [Node::class];

/**
* @var string
*/
protected $targetType = 'string';

/**
* @var integer
*/
protected $priority = 1;

/**
* @param Node $source
* @param string $targetType
* @param array<string,mixed> $subProperties
* @return mixed|\Neos\Error\Messages\Error|string|null
*/
public function convertFrom(
$source,
$targetType = null,
array $subProperties = [],
PropertyMappingConfigurationInterface $configuration = null
) {
$contentRepository = $this->contentRepositoryRegistry->get(
$source->subgraphIdentity->contentRepositoryId
);
return NodeAddressFactory::create($contentRepository)->createFromNode($source)->serializeForUri();
}
}

0 comments on commit 2a2d068

Please sign in to comment.