Problem/Motivation

Classes that implement \Drupal\Core\Entity\RevisionableInterface and \Drupal\Core\Entity\TranslatableInterface are not just standalone revisionable or translatable objects, they are also Entity objects since they are in the Drupal\Core\Entity namespace.

Not extending the main interface has the drawback that when a RevisionableInterface or TranslatableInterface type hint is used in a method argument, IDEs can not provide a good developer experience because they don't offer suggestions for generic methods from EntityInterface, like id() or label().

Proposed resolution

Make \Drupal\Core\Entity\RevisionableInterface and \Drupal\Core\Entity\TranslatableInterface extend the generic \Drupal\Core\Entity\EntityInterface.

Same for the storage counterparts and all the other specialized interfaces.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

Specialized interfaces such as EntityPublishedInterface now extend \Drupal\Core\Entity\EntityInterface.

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
StatusFileSize
new2.38 KB

This should do it.

Status: Needs review » Needs work

The last submitted patch, 2: 3028319.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new4.34 KB
new1.96 KB

Fixed those unit tests.

hchonov’s picture

This sounds like a very reasonable idea. However I think that it would be better to be consistent and cover all the interfaces that are placed unter the namespace Drupal\Core\Entity - for example SynchronizableInterface, EntityChangedInterface ....

amateescu’s picture

Title: Translatable and Revisionable entity interfaces should extend the main EntityInterface » Specialized entity interfaces should extend the main EntityInterface
Issue summary: View changes
StatusFileSize
new6.65 KB
new2.31 KB

Good point, let's do that :)

hchonov’s picture

Status: Needs review » Reviewed & tested by the community

Thank you! Looks good to me :).

catch’s picture

Alex Pott asked for feedback on the bc aspects of this.

In theory we're changing the expectations when you implement one of these interfaces.

In practice we only expect these to be implemented on top of EntityInterface, and we have the Entity base class that you're supposed to implement with that, so I think the change is OK - although it should have a change record.

effulgentsia’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

So let's get a change record for this.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
alexpott’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Committed 5d1589b and pushed to 8.7.x. Thanks!

  • alexpott committed 5d1589b on 8.7.x
    Issue #3028319 by amateescu: Specialized entity interfaces should extend...
wim leers’s picture

4 days to refactor entity interfaces and have it committed. That must be a record. Congrats!

alexpott’s picture

I forgot to credit @hchonov - ticking the box now so at least drupal.org is correct.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.