Skip to content

Commit

Permalink
Do not throw exception on unsupported provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn committed Jul 24, 2024
1 parent 34ccb32 commit 575bd93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Content/ContentTypeResolver/SmartContentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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();

Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 575bd93

Please sign in to comment.