Skip to content

Commit 575bd93

Browse files
committed
Do not throw exception on unsupported provider
1 parent 34ccb32 commit 575bd93

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Content/ContentTypeResolver/SmartContentResolver.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Sulu\Component\Content\Compat\PropertyParameter;
2323
use Sulu\Component\SmartContent\DataProviderAliasInterface;
2424
use Sulu\Component\Tag\Request\TagRequestHandlerInterface;
25-
use Sulu\Exception\FeatureNotImplementedException;
2625
use Symfony\Component\HttpFoundation\RequestStack;
2726

2827
class SmartContentResolver implements ContentTypeResolverInterface
@@ -85,6 +84,12 @@ public function resolve($result, PropertyInterface $property, string $locale, ar
8584
{
8685
// gather data provider and effective parameters
8786
$providerResolver = $this->getProviderResolver($property);
87+
88+
if ($providerResolver === null) {
89+
// Return null if no provider is registered
90+
return new ContentView(null, \is_array($result) ? $result : []);
91+
}
92+
8893
/** @var PropertyParameter[] $params */
8994
$params = \array_merge(
9095
$this->getDefaultParams($providerResolver),
@@ -166,7 +171,7 @@ public function resolve($result, PropertyInterface $property, string $locale, ar
166171
return new ContentView($result->getItems(), $viewData);
167172
}
168173

169-
private function getProviderResolver(PropertyInterface $property): DataProviderResolverInterface
174+
private function getProviderResolver(PropertyInterface $property): ?DataProviderResolverInterface
170175
{
171176
$params = $property->getParams();
172177

@@ -176,11 +181,7 @@ private function getProviderResolver(PropertyInterface $property): DataProviderR
176181
$providerAlias = $params['provider']->getValue();
177182
}
178183

179-
if (!\array_key_exists($providerAlias, $this->resolvers)) {
180-
throw new FeatureNotImplementedException();
181-
}
182-
183-
return $this->resolvers[$providerAlias];
184+
return $this->resolvers[$providerAlias] ?? null;
184185
}
185186

186187
/**

Tests/Unit/Content/ContentTypeResolver/SmartContentResolverTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,12 @@ public function testResolvePaginated(): void
272272

273273
public function testResolveMissingProviderResolver(): void
274274
{
275-
$this->expectException(FeatureNotImplementedException::class);
276-
277275
$property = $this->prophesize(PropertyInterface::class);
278276
$property->getParams()->willReturn(['provider' => new PropertyParameter('provider', 'contact')]);
279277

280-
$this->smartContentResolver->resolve([], $property->reveal(), 'en');
278+
$result = $this->smartContentResolver->resolve(['key' => 'value'], $property->reveal(), 'en');
279+
280+
self::assertNull($result->getContent());
281+
self::assertSame(['key' => 'value'], $result->getView());
281282
}
282283
}

0 commit comments

Comments
 (0)