diff --git a/Repository/PermissionCriterionResolver.php b/Repository/PermissionCriterionResolver.php index 93384737b..7f5c8a6db 100644 --- a/Repository/PermissionCriterionResolver.php +++ b/Repository/PermissionCriterionResolver.php @@ -21,8 +21,9 @@ interface PermissionCriterionResolver * * @param string $module * @param string $function + * @param array|null $targets * * @return bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion */ - public function getPermissionsCriterion($module, $function); + public function getPermissionsCriterion($module, $function, ?array $targets = null); } diff --git a/Repository/SectionService.php b/Repository/SectionService.php index 77ec5467b..c75159e07 100644 --- a/Repository/SectionService.php +++ b/Repository/SectionService.php @@ -8,6 +8,7 @@ */ namespace eZ\Publish\API\Repository; +use eZ\Publish\API\Repository\Values\Content\Location; use eZ\Publish\API\Repository\Values\Content\SectionCreateStruct; use eZ\Publish\API\Repository\Values\Content\ContentInfo; use eZ\Publish\API\Repository\Values\Content\Section; @@ -111,6 +112,15 @@ public function isSectionUsed(Section $section); */ public function assignSection(ContentInfo $contentInfo, Section $section); + /** + * Assigns the subtree to the given section + * this method overrides the current assigned section. + * + * @param \eZ\Publish\API\Repository\Values\Content\Location $location + * @param \eZ\Publish\API\Repository\Values\Content\Section $section + */ + public function assignSectionToSubtree(Location $location, Section $section): void; + /** * Deletes $section from content repository. * diff --git a/Repository/Tests/SectionServiceTest.php b/Repository/Tests/SectionServiceTest.php index 51c69207d..b2be0bea6 100644 --- a/Repository/Tests/SectionServiceTest.php +++ b/Repository/Tests/SectionServiceTest.php @@ -588,6 +588,58 @@ public function testAssignSection() ); } + /** + * Test for the assignSectionToSubtree() method. + * + * @see \eZ\Publish\API\Repository\SectionService::assignSectionToSubtree() + * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection + */ + public function testAssignSectionToSubtree() + { + $repository = $this->getRepository(); + $sectionService = $repository->getSectionService(); + + $standardSectionId = $this->generateId('section', 1); + $mediaSectionId = $this->generateId('section', 3); + + $beforeStandardCount = $sectionService->countAssignedContents( + $sectionService->loadSection($standardSectionId) + ); + + $beforeMediaCount = $sectionService->countAssignedContents( + $sectionService->loadSection($mediaSectionId) + ); + + // RemoteId of the "Media" page of an eZ Publish demo installation + $mediaRemoteId = '75c715a51699d2d309a924eca6a95145'; + + /* BEGIN: Use Case */ + $locationService = $repository->getLocationService(); + + // Load a location instance + $location = $locationService->loadLocationByRemoteId($mediaRemoteId); + + // Load the "Standard" section + $section = $sectionService->loadSection($standardSectionId); + + // Assign Section to ContentInfo + $sectionService->assignSectionToSubtree($location, $section); + + /* END: Use Case */ + $this->assertEquals( + $beforeStandardCount + 4, + $sectionService->countAssignedContents( + $sectionService->loadSection($standardSectionId) + ) + ); + $this->assertEquals( + $beforeMediaCount - 4, + $sectionService->countAssignedContents( + $sectionService->loadSection($mediaSectionId) + ) + ); + } + /** * Test for the countAssignedContents() method. *