Skip to content

Commit 12397d1

Browse files
committed
Add data fixture from entity_reference_revisions
issue #438
1 parent a950fd5 commit 12397d1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/src/Rules/EntityQueryHasAccessCheckRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public function cases(): \Generator
4444
],
4545
],
4646
];
47+
48+
yield [
49+
[__DIR__ . '/data/bug-438.php'],
50+
[]
51+
];
4752
}
4853
}

tests/src/Rules/data/bug-438.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace EntityReferenceRevisionsExample;
4+
5+
use Drupal\Core\Entity\ContentEntityInterface;
6+
use Drupal\Core\Entity\EntityTypeManagerInterface;
7+
8+
class Foo {
9+
private EntityTypeManagerInterface $entityTypeManager;
10+
public function __construct(EntityTypeManagerInterface $entityTypeManager)
11+
{
12+
$this->entityTypeManager = $entityTypeManager;
13+
}
14+
public function deleteUnusedRevision(ContentEntityInterface $composite_revision) {
15+
$composite_storage = $this->entityTypeManager->getStorage($composite_revision->getEntityTypeId());
16+
17+
if ($composite_revision->isDefaultRevision()) {
18+
$count = $composite_storage
19+
->getQuery()
20+
->accessCheck(FALSE)
21+
->allRevisions()
22+
->condition($composite_storage->getEntityType()->getKey('id'), $composite_revision->id())
23+
->count()
24+
->execute();
25+
if ($count <= 1) {
26+
$composite_revision->delete();
27+
return TRUE;
28+
}
29+
}
30+
else {
31+
// Delete the revision if this is not the default one.
32+
$composite_storage->deleteRevision($composite_revision->getRevisionId());
33+
return TRUE;
34+
}
35+
36+
return FALSE;
37+
}
38+
}

0 commit comments

Comments
 (0)