Skip to content

Infer the entity class from loadRevision(), loadRevisionUnchanged() and loadMultipleRevisions() - #1099

Open
mstrelan wants to merge 1 commit into
mglaman:mainfrom
mstrelan:storage-load-revision-return-type
Open

mstrelan wants to merge 1 commit into
mglaman:mainfrom
mstrelan:storage-load-revision-return-type

Conversation

@mstrelan

Copy link
Copy Markdown
Contributor

EntityStorageDynamicReturnTypeExtension already narrows load(), loadUnchanged(), loadMultiple(), loadByProperties() and create() to the entity class when the storage's entity type is known. The revision loaders were left out, so this still reports an undefined method:

$revision = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid);
$revision->getTranslation('fr');

This adds loadRevision(), loadRevisionUnchanged() and loadMultipleRevisions() to the supported methods.

The new methods are only narrowed when the entity type ID is known (an EntityStorageType). For a storage that is only typed as RevisionableStorageInterface, EntityDataRepository::resolveFromStorage() returns the first mapped entity type whose storage matches, such as block_content, which would give the wrong class. In that case the declared return type is kept. The existing methods are unchanged.

Measured against Drupal core main without its baseline, over the 147 files that call these methods: 28 errors removed (22 baseline entries), none added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant