Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-29518: ContentType option "Default field for sorting children" has no effect on new created objects #2428

Merged
merged 5 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions eZ/Publish/Core/REST/Client/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use eZ\Publish\Core\REST\Common\Input\Dispatcher;
use eZ\Publish\Core\REST\Common\Output\Visitor;
use eZ\Publish\Core\REST\Common\Message;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;

/**
* Location service, used for complex subtree operations.
Expand Down Expand Up @@ -79,16 +80,21 @@ public function setSession($id)
* Instantiates a new location create class.
*
* @param mixed $parentLocationId the parent under which the new location should be created
* @param eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
*
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
public function newLocationCreateStruct($parentLocationId)
public function newLocationCreateStruct($parentLocationId, ContentType $contentType = null)
{
return new LocationCreateStruct(
array(
'parentLocationId' => $parentLocationId,
)
);
$properties = [
'parentLocationId' => $parentLocationId,
];
if ($contentType) {
$properties['sortField'] = $contentType->defaultSortField;
$properties['sortOrder'] = $contentType->defaultSortOrder;
}

return new LocationCreateStruct($properties);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion eZ/Publish/Core/REST/Server/Controller/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,12 @@ protected function parseContentRequest(Request $request)
protected function doCreateContent(Request $request, RestContentCreateStruct $contentCreate)
{
try {
$contentCreateStruct = $contentCreate->contentCreateStruct;
$contentCreate->locationCreateStruct->sortField = $contentCreateStruct->contentType->defaultSortField;
$contentCreate->locationCreateStruct->sortOrder = $contentCreateStruct->contentType->defaultSortOrder;

$content = $this->repository->getContentService()->createContent(
$contentCreate->contentCreateStruct,
$contentCreateStruct,
array($contentCreate->locationCreateStruct)
);
} catch (ContentValidationException $e) {
Expand Down
9 changes: 9 additions & 0 deletions eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
use eZ\Publish\API\Repository\Values\Content\Language;
use eZ\Publish\Core\Repository\Values\Content\Location;
use eZ\Publish\SPI\Persistence\Handler;
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct as APIContentUpdateStruct;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
Expand Down Expand Up @@ -875,6 +876,14 @@ protected function buildSPILocationCreateStructs(array $locationCreateStructs)
);
}

if (!array_key_exists($locationCreateStruct->sortField, Location::SORT_FIELD_MAP)) {
$locationCreateStruct->sortField = Location::SORT_FIELD_NAME;
}

if (!array_key_exists($locationCreateStruct->sortOrder, Location::SORT_ORDER_MAP)) {
$locationCreateStruct->sortOrder = Location::SORT_ORDER_ASC;
}

$parentLocationIdSet[$locationCreateStruct->parentLocationId] = true;
$parentLocation = $this->repository->getLocationService()->loadLocation(
$locationCreateStruct->parentLocationId
Expand Down
18 changes: 12 additions & 6 deletions eZ/Publish/Core/Repository/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Exception;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;

/**
* Location service, used for complex subtree operations.
Expand Down Expand Up @@ -722,16 +723,21 @@ public function deleteLocation(APILocation $location)
* Instantiates a new location create class.
*
* @param mixed $parentLocationId the parent under which the new location should be created
* @param eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
*
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
public function newLocationCreateStruct($parentLocationId)
public function newLocationCreateStruct($parentLocationId, ContentType $contentType = null)
{
return new LocationCreateStruct(
array(
'parentLocationId' => $parentLocationId,
)
);
$properties = [
'parentLocationId' => $parentLocationId,
];
if ($contentType) {
$properties['sortField'] = $contentType->defaultSortField;
$properties['sortOrder'] = $contentType->defaultSortOrder;
}

return new LocationCreateStruct($properties);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions eZ/Publish/Core/SignalSlot/LocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use eZ\Publish\Core\SignalSlot\Signal\LocationService\UnhideLocationSignal;
use eZ\Publish\Core\SignalSlot\Signal\LocationService\MoveSubtreeSignal;
use eZ\Publish\Core\SignalSlot\Signal\LocationService\DeleteLocationSignal;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;

/**
* LocationService class.
Expand Down Expand Up @@ -350,12 +351,13 @@ public function deleteLocation(Location $location)
* Instantiates a new location create class.
*
* @param mixed $parentLocationId the parent under which the new location should be created
* @param eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
*
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
*/
public function newLocationCreateStruct($parentLocationId)
public function newLocationCreateStruct($parentLocationId, ContentType $contentType = null)
{
return $this->service->newLocationCreateStruct($parentLocationId);
return $this->service->newLocationCreateStruct($parentLocationId, $contentType);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion eZ/Publish/Core/SignalSlot/Tests/LocationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function serviceProvider()
),
array(
'newLocationCreateStruct',
array($rootId),
array($rootId, null),
$locationCreateStruct,
0,
),
Expand Down