diff --git a/src/lib/Tests/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypesTest.php b/src/lib/Tests/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypesTest.php index fbc83e1c37..981db10fb2 100644 --- a/src/lib/Tests/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypesTest.php +++ b/src/lib/Tests/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypesTest.php @@ -64,12 +64,9 @@ public function testUdwConfigResolveOnUnsupportedConfigName(): void $this->assertEquals([], $event->getConfig()); } - /** - * @dataProvider dataProviderForUdwConfigResolveWhenThereIsNoContentReadLimitations - */ - public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(bool $hasAccess): void + public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(): void { - $this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn($hasAccess); + $this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(true); $this->permissionChecker->expects($this->never())->method('getRestrictions'); $this->contentTypeService->expects($this->never())->method('loadContentTypeList'); @@ -78,12 +75,15 @@ public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(bool $ha ]); } - public function dataProviderForUdwConfigResolveWhenThereIsNoContentReadLimitations(): iterable + public function testUdwConfigResolveWhenThereIsNoContentReadLimitationsAndNoAccess(): void { - return [ - ['hasAccess' => false], - ['hasAccess' => true], - ]; + $this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(false); + $this->permissionChecker->expects($this->never())->method('getRestrictions'); + $this->contentTypeService->expects($this->never())->method('loadContentTypeList'); + + $this->assertConfigurationResolvingResult([ + 'allowed_content_types' => [null], + ]); } public function testUdwConfigResolveWhenThereAreContentReadLimitations(): void diff --git a/src/lib/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypes.php b/src/lib/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypes.php index 9d0083cc08..06454f2541 100644 --- a/src/lib/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypes.php +++ b/src/lib/UniversalDiscovery/Event/Subscriber/RichTextEmbedAllowedContentTypes.php @@ -42,16 +42,16 @@ public function __construct( /** * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException */ - private function getAllowedContentTypesIdentifiers(): array + private function getAllowedContentTypesIdentifiers(array $contentTypesAllowedViaConfig): ?array { $access = $this->permissionResolver->hasAccess('content', 'read'); if (!\is_array($access)) { - return []; + return $access ? ($contentTypesAllowedViaConfig ?: null) : [null]; } $restrictedContentTypesIds = $this->permissionChecker->getRestrictions($access, ContentTypeLimitation::class); if (empty($restrictedContentTypesIds)) { - return []; + return $contentTypesAllowedViaConfig ?: null; } $allowedContentTypesIdentifiers = []; @@ -61,7 +61,11 @@ private function getAllowedContentTypesIdentifiers(): array $allowedContentTypesIdentifiers[] = $contentType->identifier; } - return $allowedContentTypesIdentifiers; + $allowedContentTypesIdentifiers = count($contentTypesAllowedViaConfig) + ? array_intersect($contentTypesAllowedViaConfig, $allowedContentTypesIdentifiers) + : $allowedContentTypesIdentifiers; + + return empty($allowedContentTypesIdentifiers) ? [null] : array_values($allowedContentTypesIdentifiers); } public static function getSubscribedEvents(): array @@ -80,10 +84,10 @@ public function onUdwConfigResolve(ConfigResolveEvent $event): void } if ($this->allowedContentTypesIdentifiers === null) { - $this->allowedContentTypesIdentifiers = $this->getAllowedContentTypesIdentifiers(); + $this->allowedContentTypesIdentifiers = $this->getAllowedContentTypesIdentifiers($config['allowed_content_types'] ?? []); } - $config['allowed_content_types'] = !empty($this->allowedContentTypesIdentifiers) ? $this->allowedContentTypesIdentifiers : null; + $config['allowed_content_types'] = $this->allowedContentTypesIdentifiers; $event->setConfig($config); }