From 575bd9348fe76648d584d492f3abaf8aa61063cd Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Wed, 24 Jul 2024 15:17:36 +0200 Subject: [PATCH] Do not throw exception on unsupported provider --- .../ContentTypeResolver/SmartContentResolver.php | 15 ++++++++------- .../SmartContentResolverTest.php | 7 ++++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Content/ContentTypeResolver/SmartContentResolver.php b/Content/ContentTypeResolver/SmartContentResolver.php index 9603b6e..1abe093 100644 --- a/Content/ContentTypeResolver/SmartContentResolver.php +++ b/Content/ContentTypeResolver/SmartContentResolver.php @@ -22,7 +22,6 @@ use Sulu\Component\Content\Compat\PropertyParameter; use Sulu\Component\SmartContent\DataProviderAliasInterface; use Sulu\Component\Tag\Request\TagRequestHandlerInterface; -use Sulu\Exception\FeatureNotImplementedException; use Symfony\Component\HttpFoundation\RequestStack; class SmartContentResolver implements ContentTypeResolverInterface @@ -85,6 +84,12 @@ public function resolve($result, PropertyInterface $property, string $locale, ar { // gather data provider and effective parameters $providerResolver = $this->getProviderResolver($property); + + if ($providerResolver === null) { + // Return null if no provider is registered + return new ContentView(null, \is_array($result) ? $result : []); + } + /** @var PropertyParameter[] $params */ $params = \array_merge( $this->getDefaultParams($providerResolver), @@ -166,7 +171,7 @@ public function resolve($result, PropertyInterface $property, string $locale, ar return new ContentView($result->getItems(), $viewData); } - private function getProviderResolver(PropertyInterface $property): DataProviderResolverInterface + private function getProviderResolver(PropertyInterface $property): ?DataProviderResolverInterface { $params = $property->getParams(); @@ -176,11 +181,7 @@ private function getProviderResolver(PropertyInterface $property): DataProviderR $providerAlias = $params['provider']->getValue(); } - if (!\array_key_exists($providerAlias, $this->resolvers)) { - throw new FeatureNotImplementedException(); - } - - return $this->resolvers[$providerAlias]; + return $this->resolvers[$providerAlias] ?? null; } /** diff --git a/Tests/Unit/Content/ContentTypeResolver/SmartContentResolverTest.php b/Tests/Unit/Content/ContentTypeResolver/SmartContentResolverTest.php index 190cf36..b6ad8be 100644 --- a/Tests/Unit/Content/ContentTypeResolver/SmartContentResolverTest.php +++ b/Tests/Unit/Content/ContentTypeResolver/SmartContentResolverTest.php @@ -272,11 +272,12 @@ public function testResolvePaginated(): void public function testResolveMissingProviderResolver(): void { - $this->expectException(FeatureNotImplementedException::class); - $property = $this->prophesize(PropertyInterface::class); $property->getParams()->willReturn(['provider' => new PropertyParameter('provider', 'contact')]); - $this->smartContentResolver->resolve([], $property->reveal(), 'en'); + $result = $this->smartContentResolver->resolve(['key' => 'value'], $property->reveal(), 'en'); + + self::assertNull($result->getContent()); + self::assertSame(['key' => 'value'], $result->getView()); } }