File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -44,5 +44,10 @@ public function cases(): \Generator
44
44
],
45
45
],
46
46
];
47
+
48
+ yield [
49
+ [__DIR__ . '/data/bug-438.php ' ],
50
+ []
51
+ ];
47
52
}
48
53
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments