Skip to content

Commit

Permalink
Do not throw exception on unsupported provider (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prokyonn authored Jul 24, 2024
1 parent ef8b826 commit 8048a55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 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 (null === $providerResolver) {
// 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 @@ -29,7 +29,6 @@
use Sulu\Component\Content\Compat\StructureInterface;
use Sulu\Component\SmartContent\Configuration\ProviderConfigurationInterface;
use Sulu\Component\Tag\Request\TagRequestHandlerInterface;
use Sulu\Exception\FeatureNotImplementedException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

Expand Down Expand Up @@ -272,11 +271,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 8048a55

Please sign in to comment.