Skip to content

Commit 6cee8fa

Browse files
committed
Fix, delete position if we are deleting a draft and no live component
1 parent a1e01bf commit 6cee8fa

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

features/publishable/publishable.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,12 @@ Feature: Access to unpublished/draft resources should be configurable
413413
And the resource component_position should exist
414414
And the resource publishable_draft should exist
415415
And the resource publishable_published should not exist
416+
417+
@loginAdmin
418+
Scenario: When deleting a component the component position should NOT be deleted if a draft component exists as well
419+
Given there is a publishable resource set to publish at "2999-12-31T23:59:59+00:00"
420+
And there is a ComponentPosition with the resource "publishable_draft"
421+
When I send a "DELETE" request to the resource "publishable_draft" and the postfix "?published=false"
422+
Then the response status code should be 204
423+
And the resource component_position should not exist
424+
And the resource publishable_draft should not exist

src/EventListener/Api/ComponentPositionEventListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ private function removeEmptyPositions(ViewEvent $event): void
8383
$configuration = $this->publishableAttributeReader->getConfiguration($className);
8484
$classMetadata = $this->getClassMetadata($className);
8585
$draftResource = $classMetadata->getFieldValue($data, $configuration->reverseAssociationName) ?? $data;
86-
if ($draftResource) {
86+
87+
if ($draftResource && $data !== $draftResource) {
8788
foreach ($positions as $position) {
8889
$position->component = $draftResource;
8990
}

0 commit comments

Comments
 (0)