Problem/Motivation
#2942907: Entity system does not provide an API for retrieving an entity variant that is safe for editing added the concept of "active variant" of an entity and API methods to retrieve, but we also need an API for determining whether an entity object is active, similar to \Drupal\Core\Entity\RevisionableInterface::isLatestRevision() and \Drupal\Core\Entity\TranslatableRevisionableInterface::isRevisionTranslationAffected().
Proposed resolution
Add a isActive() method to \Drupal\Core\Experimental\Entity\EntityRepositoryInterface.
Remaining tasks
Discuss, review, etc.
User interface changes
Nope.
API changes
API addition: a new method on \Drupal\Core\Experimental\Entity\EntityRepositoryInterface.
Data model changes
Nope.
Release notes snippet
Nope.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3037247-5.patch | 2.06 KB | amateescu |
| #2 | 3037247.patch | 2.3 KB | amateescu |
Comments
Comment #2
amateescu commentedBringing over the patch from #2942907-116: Entity system does not provide an API for retrieving an entity variant that is safe for editing.
Comment #3
amateescu commentedThe parent issue was committed, we can resume work here :)
Comment #5
amateescu commentedRerolled.
Comment #7
johnwebdev commentedWhy is a static cache needed to ensure identity right now?
Comment #8
amateescu commentedNot sure what you mean by "right now", and this is about equality, not identity :)
The reason why I think we should perform a strict equality check against a static cache is because of the way PHP compares objects (http://php.net/manual/en/language.oop5.object-comparison.php), and I'm worried that a loose equality check would be very expensive for our entity objects, which have *a lot* of properties and some of them might even lead to infinite recursion.
However, on a second thought, it may be better to introduce an
EntityInterface::equals()method, just like we have for field item lists, because at least we can optimize that one as much as possible.Comment #9
johnwebdev commentedSorry, I misinterpreted your @todo, and I simply meant why we didn't compare the arrays ===, (which is called identity, http://php.net/manual/en/language.operators.array.php)
Do we really need to check all the values to know if it is active though?
The ::equals sounds like a good idea :)