Skip to content

Commit 7ca493e

Browse files
authored
Allow LocationCreateStruct objects inside the $locations argument of ContentCreateStructure to have more control over the created locations. (#40)
1 parent 4739687 commit 7ca493e

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 3.1.0
2+
3+
* Allow `LocationCreateStruct` objects inside the `$locations` argument of `ContentCreateStructure` to have more control over the created locations.
4+
15
# Version 3.0.1
26

37
* Bump minimum PHP version to PHP 7.3 like code-rhapsodie/dataflow-bundle dependency.

src/Core/Content/ContentCreator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ private function getLocationCreateStructs(array $locations): array
6060
{
6161
$locationCreateStructs = [];
6262

63-
foreach ($locations as $locationOrIdOrRemoteId) {
63+
foreach ($locations as $locationOrIdOrRemoteIdOrStruct) {
64+
if ($locationOrIdOrRemoteIdOrStruct instanceof LocationCreateStruct) {
65+
$locationCreateStructs[] = $locationOrIdOrRemoteIdOrStruct;
66+
67+
continue;
68+
}
69+
6470
$locationCreateStructs[] = new LocationCreateStruct([
65-
'parentLocationId' => $this->matcher->matchLocation($locationOrIdOrRemoteId)->id,
71+
'parentLocationId' => $this->matcher->matchLocation($locationOrIdOrRemoteIdOrStruct)->id,
6672
]);
6773
}
6874

src/Model/ContentCreateStructure.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use CodeRhapsodie\EzDataflowBundle\Exception\InvalidArgumentTypeException;
88
use eZ\Publish\API\Repository\Values\Content\Location;
9+
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
910

1011
class ContentCreateStructure extends ContentStructure
1112
{
@@ -24,6 +25,7 @@ class ContentCreateStructure extends ContentStructure
2425
* <li>an integer, the id of the Location object</li>
2526
* <li>a string, the remote id of the Location object</li>
2627
* <li>a Location object</li>
28+
* <li>a LocationCreateStruct object</li>
2729
* </ul>
2830
*
2931
* @throws InvalidArgumentTypeException
@@ -52,12 +54,13 @@ public function getLocations(): array
5254
*/
5355
private function setLocations(array $locations)
5456
{
55-
foreach ($locations as $locationOrIdOrRemoteId) {
56-
if (!is_int($locationOrIdOrRemoteId)
57-
&& !is_string($locationOrIdOrRemoteId)
58-
&& !$locationOrIdOrRemoteId instanceof Location
57+
foreach ($locations as $locationOrIdOrRemoteIdOrStruct) {
58+
if (!is_int($locationOrIdOrRemoteIdOrStruct)
59+
&& !is_string($locationOrIdOrRemoteIdOrStruct)
60+
&& !$locationOrIdOrRemoteIdOrStruct instanceof Location
61+
&& !$locationOrIdOrRemoteIdOrStruct instanceof LocationCreateStruct
5962
) {
60-
throw InvalidArgumentTypeException::create(['int', 'string', Location::class], $locationOrIdOrRemoteId);
63+
throw InvalidArgumentTypeException::create(['int', 'string', Location::class, LocationCreateStruct::class], $locationOrIdOrRemoteIdOrStruct);
6164
}
6265
}
6366

0 commit comments

Comments
 (0)