Details
-
Bug
-
Resolution: Done
-
High
-
2.5.14
-
None
Description
We accidentally created the forms folder at parent Location 2 and want to move it to parent Location 1 via Public API
$this->repo->sudo(
function (Repository $repo) {
$locSvc = $repo->getLocationService();
$form = $locSvc->loadLocation(58);
$parent = $locSvc->loadLocation(1);
$repo->getLocationService()->moveSubtree($form, $parent);
}
);
But then get an error
Type error: Return value of eZ\Publish\Core\Repository\Values\Content\Conte
nt::getContentType() must be an instance of eZ\Publish\API\Repository\Value
s\ContentType\ContentType, null returned
This is because the special location 1 has no content (id 0) although it has a content-type 1 (folder).
The check in vendor/ezsystems/ezpublish-kernel/eZ/Publish/Core/Repository/LocationService.php Line 675 is the cause, because it tries to fetch the content-type from the content instead of the location.
if (!$newParentLocation->getContent()->getContentType()->isContainer)
Solution: Fetch the contentType via the contentTypeId attached to the location and then do the check.
//Note from support:
the same situation occurs for:
- copySubtree
- swapLocation
- updating mainLocationId