Skip to content

Commit

Permalink
Use structure language instead of property value as locale (#129)
Browse files Browse the repository at this point in the history
* Use structure language instead of property value as locale

* Fix test
  • Loading branch information
Prokyonn authored Jul 19, 2023
1 parent 9ec2faa commit d5c846e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Content/ContentTypeResolver/LinkResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private function getViewData(PropertyInterface $property): array
private function getContentData(PropertyInterface $property): ?string
{
$value = $property->getValue();
$locale = $property->getStructure()->getLanguageCode();

if (!$value || !isset($value['provider'])) {
return null;
Expand All @@ -90,7 +91,7 @@ private function getContentData(PropertyInterface $property): ?string

$provider = $this->linkProviderPool->getProvider($value['provider']);

$linkItems = $provider->preload([$value['href']], $value['locale']);
$linkItems = $provider->preload([$value['href']], $locale);

if (0 === \count($linkItems)) {
return null;
Expand Down
17 changes: 17 additions & 0 deletions Tests/Unit/Content/ContentTypeResolver/LinkResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkProviderInterface;
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkProviderPoolInterface;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\Compat\StructureInterface;

class LinkResolverTest extends TestCase
{
Expand All @@ -37,7 +38,15 @@ public function testResolve(): void
$provider = $this->prophesize(LinkProviderInterface::class);
$linkResolver = new LinkResolver($providerPool->reveal());

$structure = $this->prophesize(StructureInterface::class);
$structure->getLanguageCode()
->shouldBeCalled()
->willReturn('en');

$property = $this->prophesize(PropertyInterface::class);
$property->getStructure()
->shouldBeCalled()
->wilLReturn($structure->reveal());
$property->getValue()
->shouldBeCalled()
->willReturn([
Expand Down Expand Up @@ -81,7 +90,15 @@ public function testResolveMinimal(): void
$provider = $this->prophesize(LinkProviderInterface::class);
$linkResolver = new LinkResolver($providerPool->reveal());

$structure = $this->prophesize(StructureInterface::class);
$structure->getLanguageCode()
->shouldBeCalled()
->willReturn('en');

$property = $this->prophesize(PropertyInterface::class);
$property->getStructure()
->shouldBeCalled()
->wilLReturn($structure->reveal());
$property->getValue()
->shouldBeCalled()
->willReturn([
Expand Down

0 comments on commit d5c846e

Please sign in to comment.