From bbe3c442209356508441407770348ea58fc9e195 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Tue, 12 Oct 2021 14:01:07 +0200 Subject: [PATCH] Add method to preview-provider for public-preview (#207) --- .../Sulu/Preview/ContentObjectProvider.php | 14 +++++++++++++- .../Sulu/Preview/ContentObjectProviderTest.php | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php b/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php index e0c13f47..fa80481c 100644 --- a/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php +++ b/Content/Infrastructure/Sulu/Preview/ContentObjectProvider.php @@ -45,6 +45,11 @@ class ContentObjectProvider implements PreviewObjectProviderInterface */ private $contentRichEntityClass; + /** + * @var string|null + */ + private $securityContext; + /** * @param class-string $contentRichEntityClass */ @@ -52,12 +57,14 @@ 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; } /** @@ -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 { diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php index f3273811..119b5fce 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Preview/ContentObjectProviderTest.php @@ -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 @@ -62,7 +63,8 @@ protected function setUp(): void $this->entityManager->reveal(), $this->contentResolver->reveal(), $this->contentDataMapper->reveal(), - Example::class + Example::class, + ExampleAdmin::SECURITY_CONTEXT ); } @@ -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') + ); + } }