forked from neos/neos-development-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Re introduce hacky node converters, to be removed via neos#4873
- Loading branch information
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
Neos.Neos/Classes/TypeConverter/HackyNodeAddressToNodeConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Neos.Neos/Classes/TypeConverter/NodeToNodeAddressStringConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |