Skip to content

Commit 6dc228e

Browse files
authored
Add RevisionableStorageInterface::createRevision generic for return type (#894)
* createRevision returns an object instance of the same type passed to entity, but not the same object reference I cannot add stubs for RevisionableStorageInterface and TranslatableRevisionableStorageInterface in my own projects because phpstan-drupal prevents it! * `TranslatableRevisionableStorageInterface::createRevision` has a different signature and may require it * typing * another type
1 parent 42cca54 commit 6dc228e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

stubs/Drupal/Core/Entity/RevisionableStorageInterface.stub

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ interface RevisionableStorageInterface extends EntityStorageInterface {
1414
* @param int|numeric-string $revision_id
1515
*/
1616
public function deleteRevision($revision_id): void;
17+
18+
/**
19+
* @param R $entity
20+
* @return R
21+
* @template R of \Drupal\Core\Entity\RevisionableInterface
22+
*/
23+
public function createRevision(RevisionableInterface $entity, bool $default = TRUE);
1724

1825
}

stubs/Drupal/Core/Entity/TranslatableRevisionableStorageInterface.stub

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ namespace Drupal\Core\Entity;
99
// This is fragile and relies on `ContentEntityStorageInterface` only implementing this interface.
1010
interface TranslatableRevisionableStorageInterface extends RevisionableStorageInterface, TranslatableStorageInterface {
1111

12+
/**
13+
* @param R $entity
14+
* @return R
15+
* @template R of \Drupal\Core\Entity\RevisionableInterface
16+
*/
17+
public function createRevision(RevisionableInterface $entity, bool $default = TRUE, ?bool $keep_untranslatable_fields = NULL);
18+
1219
}

0 commit comments

Comments
 (0)