Skip to content

Commit ffcd518

Browse files
committed
FEATURE: Link value object with asset id as link must be indexed via asset usage
1 parent 3e44380 commit ffcd518

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ protected function deserializeProperties(array $properties): PropertyValuesToWri
296296
{
297297
return PropertyValuesToWrite::fromArray(
298298
array_map(
299-
static fn (mixed $value) => is_array($value) && isset($value['__type']) ? new $value['__type']($value['value']) : $value,
299+
static fn (mixed $value) => is_array($value) && isset($value['__type']) ? (is_array($value['value']) ? $value['__type']::fromArray($value['value']) : new $value['__type']($value['value'])) : $value,
300300
$properties
301301
)
302302
);

Neos.Neos/Classes/AssetUsage/Service/AssetUsageIndexingService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Neos\Neos\AssetUsage\Domain\AssetUsageRepository;
2525
use Neos\Neos\AssetUsage\Dto\AssetIdAndOriginalAssetId;
2626
use Neos\Neos\AssetUsage\Dto\AssetIdsByProperty;
27+
use Neos\Neos\Domain\Link\Link;
2728
use Neos\Utility\TypeHandling;
2829

2930
/**
@@ -217,6 +218,14 @@ private function extractAssetIds(string $type, mixed $value): array
217218
preg_match_all('/asset:\/\/(?<assetId>[\w-]*)/i', $value, $matches, PREG_SET_ORDER);
218219
return array_map(static fn (array $match) => $match['assetId'], $matches);
219220
}
221+
222+
if ($value instanceof Link) {
223+
if ($value->href->getScheme() === 'asset') {
224+
return [$value->href->getHost() . $value->href->getPath('')];
225+
}
226+
return [];
227+
}
228+
220229
if (is_subclass_of($type, ResourceBasedInterface::class)) {
221230
return [$this->persistenceManager->getIdentifierByObject($value)];
222231
}

Neos.Neos/Tests/Behavior/Features/AssetUsage/01-NodeCreation/01-CreateNodeAggregateWithNode_WithoutDimensions.feature

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Feature: Create node aggregate with node without dimensions
1010
properties:
1111
text:
1212
type: string
13+
assetLinkString:
14+
type: string
15+
assetLinkObject:
16+
type: Neos\Neos\Domain\Link\Link
1317
asset:
1418
type: Neos\Media\Domain\Model\Asset
1519
assets:
@@ -35,6 +39,8 @@ Feature: Create node aggregate with node without dimensions
3539
When an asset exists with id "asset-1"
3640
And an asset exists with id "asset-2"
3741
And an asset exists with id "asset-3"
42+
And an asset exists with id "asset-4"
43+
And an asset exists with id "asset-5"
3844

3945
When the command CreateWorkspace is executed with payload:
4046
| Key | Value |
@@ -46,16 +52,20 @@ Feature: Create node aggregate with node without dimensions
4652
Given I am in workspace "live"
4753

4854
And the following CreateNodeAggregateWithNode commands are executed:
49-
| nodeAggregateId | nodeName | parentNodeAggregateId | nodeTypeName | initialPropertyValues |
50-
| sir-david-nodenborough | node | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"asset": "Asset:asset-1"} |
51-
| nody-mc-nodeface | child-node | sir-david-nodenborough | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"assets": ["Asset:asset-2"]} |
52-
| sir-nodeward-nodington-iii | esquire | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"text": "Link to asset://asset-3."} |
55+
| nodeAggregateId | nodeName | parentNodeAggregateId | nodeTypeName | initialPropertyValues |
56+
| sir-david-nodenborough | node | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"asset": "Asset:asset-1"} |
57+
| nody-mc-nodeface | child-node | sir-david-nodenborough | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"assets": ["Asset:asset-2"]} |
58+
| sir-nodeward-nodington-iii | esquire | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"text": "Link to asset://asset-3."} |
59+
| sir-nodeward-lincoln | | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"assetLinkString": "asset://asset-4"} |
60+
| sir-objectward-lincoln | | lady-eleonode-rootford | Neos.ContentRepository.Testing:NodeWithAssetProperties | {"assetLinkObject": {"__type": "Neos\\\\Neos\\\\Domain\\\\Link\\\\Link", "value": { "href": "asset://asset-5" }}} |
5361

5462
Then I expect the AssetUsageService to have the following AssetUsages:
55-
| assetId | nodeAggregateId | propertyName | workspaceName | originDimensionSpacePoint |
56-
| asset-1 | sir-david-nodenborough | asset | live | {} |
57-
| asset-2 | nody-mc-nodeface | assets | live | {} |
58-
| asset-3 | sir-nodeward-nodington-iii | text | live | {} |
63+
| assetId | nodeAggregateId | propertyName | workspaceName | originDimensionSpacePoint |
64+
| asset-1 | sir-david-nodenborough | asset | live | {} |
65+
| asset-2 | nody-mc-nodeface | assets | live | {} |
66+
| asset-3 | sir-nodeward-nodington-iii | text | live | {} |
67+
| asset-4 | sir-nodeward-lincoln | assetLinkString | live | {} |
68+
| asset-5 | sir-objectward-lincoln | assetLinkObject | live | {} |
5969

6070
Scenario: Nodes on user workspace have been created
6171
Given I am in workspace "user-workspace"

0 commit comments

Comments
 (0)