Skip to content

Commit

Permalink
Add method to preview-provider for public-preview (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes authored and luca-rath committed Feb 10, 2022
1 parent 817d852 commit bbe3c44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,26 @@ class ContentObjectProvider implements PreviewObjectProviderInterface
*/
private $contentRichEntityClass;

/**
* @var string|null
*/
private $securityContext;

/**
* @param class-string<ContentRichEntityInterface> $contentRichEntityClass
*/
public function __construct(
EntityManagerInterface $entityManager,
ContentResolverInterface $contentResolver,
ContentDataMapperInterface $contentDataMapper,
string $contentRichEntityClass
string $contentRichEntityClass,
?string $securityContext = null
) {
$this->entityManager = $entityManager;
$this->contentResolver = $contentResolver;
$this->contentDataMapper = $contentDataMapper;
$this->contentRichEntityClass = $contentRichEntityClass;
$this->securityContext = $securityContext;
}

/**
Expand Down Expand Up @@ -154,6 +161,11 @@ public function deserialize($serializedObject, $objectClass)
return $this->getObject($id, $locale);
}

public function getSecurityContext($id, $locale): ?string
{
return $this->securityContext;
}

protected function resolveContent(ContentRichEntityInterface $contentRichEntity, string $locale): ?DimensionContentInterface
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Preview\ContentObjectProvider;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Preview\PreviewDimensionContentCollection;
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Admin\ExampleAdmin;
use Sulu\Bundle\ContentBundle\Tests\Application\ExampleTestBundle\Entity\Example;

class ContentObjectProviderTest extends TestCase
Expand Down Expand Up @@ -62,7 +63,8 @@ protected function setUp(): void
$this->entityManager->reveal(),
$this->contentResolver->reveal(),
$this->contentDataMapper->reveal(),
Example::class
Example::class,
ExampleAdmin::SECURITY_CONTEXT
);
}

Expand Down Expand Up @@ -310,4 +312,12 @@ public function testDeserializeLocaleNull(): void

$this->assertNull($result);
}

public function testGetSecurityContext(): void
{
$this->assertSame(
ExampleAdmin::SECURITY_CONTEXT,
$this->contentObjectProvider->getSecurityContext('123-123-123', 'en')
);
}
}

0 comments on commit bbe3c44

Please sign in to comment.