diff --git a/Repository/ContentTypeService.php b/Repository/ContentTypeService.php index c311f2865..0abd986d5 100644 --- a/Repository/ContentTypeService.php +++ b/Repository/ContentTypeService.php @@ -380,4 +380,12 @@ public function newFieldDefinitionUpdateStruct(); * @return bool */ public function isContentTypeUsed(ContentType $contentType); + + /** + * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft + * @param string $languageCode + * + * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft + */ + public function removeContentTypeTranslation(ContentTypeDraft $contentTypeDraft, string $languageCode): ContentTypeDraft; } diff --git a/Repository/Tests/ContentTypeServiceTest.php b/Repository/Tests/ContentTypeServiceTest.php index a0a4b6fad..a7e92afe8 100644 --- a/Repository/Tests/ContentTypeServiceTest.php +++ b/Repository/Tests/ContentTypeServiceTest.php @@ -4131,4 +4131,46 @@ public function testIsContentTypeUsed() $this->assertTrue($isFolderUsed); $this->assertFalse($isEventUsed); } + + /** + * @covers \eZ\Publish\API\Repository\ContentTypeService::removeContentTypeTranslation + * + * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException + * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + */ + public function testRemoveContentTypeTranslation() + { + $repository = $this->getRepository(); + $contentTypeService = $repository->getContentTypeService(); + + $contentTypeDraft = $this->createContentTypeDraft(); + $contentTypeService->publishContentTypeDraft($contentTypeDraft); + + $contentType = $contentTypeService->loadContentType($contentTypeDraft->id); + + $this->assertEquals( + [ + 'eng-US' => 'Blog post', + 'ger-DE' => 'Blog-Eintrag', + ], + $contentType->getNames() + ); + + $contentTypeService->removeContentTypeTranslation( + $contentTypeService->createContentTypeDraft($contentType), + 'ger-DE' + ); + + $loadedContentTypeDraft = $contentTypeService->loadContentTypeDraft($contentType->id); + + $this->assertArrayNotHasKey('ger-DE', $loadedContentTypeDraft->getNames()); + $this->assertArrayNotHasKey('ger-DE', $loadedContentTypeDraft->getDescriptions()); + + foreach ($loadedContentTypeDraft->fieldDefinitions as $fieldDefinition) { + $this->assertArrayNotHasKey('ger-DE', $fieldDefinition->getNames()); + $this->assertArrayNotHasKey('ger-DE', $fieldDefinition->getDescriptions()); + } + } }