From 2b2968ebf74a4980b97ae8c8b41bcad363a6937e Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 28 Oct 2025 16:04:57 +0100 Subject: [PATCH 1/4] Enhanced exception for createContent --- src/lib/Repository/ContentService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Repository/ContentService.php b/src/lib/Repository/ContentService.php index 2cee84e93a..dbadbb2c8e 100644 --- a/src/lib/Repository/ContentService.php +++ b/src/lib/Repository/ContentService.php @@ -699,7 +699,7 @@ public function createContent(APIContentCreateStruct $contentCreateStruct, array ); if (!empty($errors)) { - throw new ContentFieldValidationException($errors); + throw ContentFieldValidationException::createNewWithMultiline($errors); } $spiLocationCreateStructs = $this->buildSPILocationCreateStructs( From 812012225bafa761500057325181f818f1e332ab Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 28 Oct 2025 16:34:58 +0100 Subject: [PATCH 2/4] adapt error message --- src/lib/Base/Exceptions/ContentFieldValidationException.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Base/Exceptions/ContentFieldValidationException.php b/src/lib/Base/Exceptions/ContentFieldValidationException.php index 0b8091dca4..9e4fb37e9e 100644 --- a/src/lib/Base/Exceptions/ContentFieldValidationException.php +++ b/src/lib/Base/Exceptions/ContentFieldValidationException.php @@ -59,10 +59,10 @@ public static function createNewWithMultiline(array $errors, ?string $contentNam $exception = new self($errors); $exception->contentName = $contentName; - $exception->setMessageTemplate('Content "%contentName%" fields did not validate: %errors%'); + $exception->setMessageTemplate('Content%contentName%fields did not validate: %errors%'); $exception->setParameters([ '%errors%' => $exception->generateValidationErrorsMessages(), - '%contentName%' => $exception->contentName !== null ? $exception->contentName : '', + '%contentName%' => $exception->contentName !== null ? ' "'. $exception->contentName. '" ' : ' ', ]); $exception->message = $exception->getBaseTranslation(); From a788be63afc025dad3e82890563156884abcc611 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 28 Oct 2025 16:43:38 +0100 Subject: [PATCH 3/4] fix-cs --- src/lib/Base/Exceptions/ContentFieldValidationException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Base/Exceptions/ContentFieldValidationException.php b/src/lib/Base/Exceptions/ContentFieldValidationException.php index 9e4fb37e9e..66743cfec5 100644 --- a/src/lib/Base/Exceptions/ContentFieldValidationException.php +++ b/src/lib/Base/Exceptions/ContentFieldValidationException.php @@ -62,7 +62,7 @@ public static function createNewWithMultiline(array $errors, ?string $contentNam $exception->setMessageTemplate('Content%contentName%fields did not validate: %errors%'); $exception->setParameters([ '%errors%' => $exception->generateValidationErrorsMessages(), - '%contentName%' => $exception->contentName !== null ? ' "'. $exception->contentName. '" ' : ' ', + '%contentName%' => $exception->contentName !== null ? ' "' . $exception->contentName . '" ' : ' ', ]); $exception->message = $exception->getBaseTranslation(); From 68f1e9057fd1cef4f8db41cd9acdd9d0cc6cf885 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Wed, 5 Nov 2025 10:54:58 +0100 Subject: [PATCH 4/4] testCreateContent: Changed expected message --- src/lib/Base/Exceptions/ContentFieldValidationException.php | 4 ++-- tests/lib/Repository/Service/Mock/ContentTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/Base/Exceptions/ContentFieldValidationException.php b/src/lib/Base/Exceptions/ContentFieldValidationException.php index 66743cfec5..0b8091dca4 100644 --- a/src/lib/Base/Exceptions/ContentFieldValidationException.php +++ b/src/lib/Base/Exceptions/ContentFieldValidationException.php @@ -59,10 +59,10 @@ public static function createNewWithMultiline(array $errors, ?string $contentNam $exception = new self($errors); $exception->contentName = $contentName; - $exception->setMessageTemplate('Content%contentName%fields did not validate: %errors%'); + $exception->setMessageTemplate('Content "%contentName%" fields did not validate: %errors%'); $exception->setParameters([ '%errors%' => $exception->generateValidationErrorsMessages(), - '%contentName%' => $exception->contentName !== null ? ' "' . $exception->contentName . '" ' : ' ', + '%contentName%' => $exception->contentName !== null ? $exception->contentName : '', ]); $exception->message = $exception->getBaseTranslation(); diff --git a/tests/lib/Repository/Service/Mock/ContentTest.php b/tests/lib/Repository/Service/Mock/ContentTest.php index 339d23b203..79b228e02a 100644 --- a/tests/lib/Repository/Service/Mock/ContentTest.php +++ b/tests/lib/Repository/Service/Mock/ContentTest.php @@ -2503,7 +2503,7 @@ public function providerForTestCreateContentThrowsContentFieldValidationExceptio public function testCreateContentThrowsContentFieldValidationException($mainLanguageCode, $structFields): void { $this->expectException(ContentFieldValidationException::class); - $this->expectExceptionMessage('Content fields did not validate'); + $this->expectExceptionMessage('Content "" fields did not validate'); $fieldDefinitions = $this->fixturesForTestCreateContentNonRedundantFieldSetComplex(); list($contentCreateStruct, $allFieldErrors) =