diff --git a/lib/Parameters/ValueObjectProvider/ContentProvider.php b/lib/Parameters/ValueObjectProvider/ContentProvider.php index 7d71bcc8..4f52407d 100644 --- a/lib/Parameters/ValueObjectProvider/ContentProvider.php +++ b/lib/Parameters/ValueObjectProvider/ContentProvider.php @@ -24,6 +24,10 @@ public function __construct(Repository $repository, ErrorHandlerInterface $error public function getValueObject($value): ?Content { + if ($value === null) { + return null; + } + try { /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */ $content = $this->repository->sudo( diff --git a/lib/Parameters/ValueObjectProvider/LocationProvider.php b/lib/Parameters/ValueObjectProvider/LocationProvider.php index 078e0abd..4b2f4b84 100644 --- a/lib/Parameters/ValueObjectProvider/LocationProvider.php +++ b/lib/Parameters/ValueObjectProvider/LocationProvider.php @@ -24,6 +24,10 @@ public function __construct(Repository $repository, ErrorHandlerInterface $error public function getValueObject($value): ?Location { + if ($value === null) { + return null; + } + try { return $this->repository->sudo( static fn (Repository $repository): Location => $repository->getLocationService()->loadLocation((int) $value), diff --git a/tests/lib/Parameters/ValueObjectProvider/ContentProviderTest.php b/tests/lib/Parameters/ValueObjectProvider/ContentProviderTest.php index 398cfa35..5c4a0380 100644 --- a/tests/lib/Parameters/ValueObjectProvider/ContentProviderTest.php +++ b/tests/lib/Parameters/ValueObjectProvider/ContentProviderTest.php @@ -69,6 +69,18 @@ public function testGetValueObject(): void self::assertSame($content, $this->valueObjectProvider->getValueObject(42)); } + /** + * @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\ContentProvider::getValueObject + */ + public function testGetValueObjectWithNullValue(): void + { + $this->contentServiceMock + ->expects(self::never()) + ->method('loadContent'); + + self::assertNull($this->valueObjectProvider->getValueObject(null)); + } + /** * @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\ContentProvider::getValueObject */ diff --git a/tests/lib/Parameters/ValueObjectProvider/LocationProviderTest.php b/tests/lib/Parameters/ValueObjectProvider/LocationProviderTest.php index 6b3909b6..a7492338 100644 --- a/tests/lib/Parameters/ValueObjectProvider/LocationProviderTest.php +++ b/tests/lib/Parameters/ValueObjectProvider/LocationProviderTest.php @@ -59,6 +59,18 @@ public function testGetValueObject(): void self::assertSame($location, $this->valueObjectProvider->getValueObject(42)); } + /** + * @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\LocationProvider::getValueObject + */ + public function testGetValueObjectWithNullValue(): void + { + $this->locationServiceMock + ->expects(self::never()) + ->method('loadLocation'); + + self::assertNull($this->valueObjectProvider->getValueObject(null)); + } + /** * @covers \Netgen\Layouts\Ez\Parameters\ValueObjectProvider\LocationProvider::getValueObject */