\Drupal\user\UserInterface
extends \Drupal\Core\Entity\ContentEntityInterface
which extends \Drupal\Core\Entity\RevisionableInterface
.
Same goes for a whole bunch of other interfaces that extend ContentEntityInterface
: those for File, , MenuLinkContent and so on.
But \Drupal\user\Entity\User
does not support revisions at all. It's caught in ContentEntityBase
:
public function setNewRevision($value = TRUE) {
if (!$this->getEntityType()->hasKey('revision')) {
throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions.");
}
This means you can't do this:
if ($entity instanceof RevisionableInterface) {
$entity->setNewRevision(FALSE);
}
We shouldn't be violating the interfaces we're implementing.
Comment | File | Size | Author |
---|---|---|---|
#22 | 2822611_22.patch | 5.15 KB | Mile23 |
Comments
Comment #2
Wim LeersComment #3
dawehnerWell, ideally the revision stuff would live on
\Drupal\Core\Entity\RevisionableContentEntityBase
or a corresponding interface. At least the issue title as it is, is highly misleading :)Comment #4
BerdirYeah, we discussed this in IRC, the correct way to identify this is not this interface but to use isRevisionable() on the entity type, which basically checks if here is a revision entity key.
All content entities implement this interface, the reason is that they all *technically* support revisions just like they all technically support revisions and translations. Whether they actually have a its a question of storage/storage configuration, which is done in the annotation and that can be changed with alter hooks.
Changing to a documentation task as Wim promised to do (he said he'll close it actually, IIRC)
Comment #5
Wim LeersComment #6
dawehnerThank you wim! I hope this clarifies the situation up.
Comment #7
alexpottCommitted and pushed 481a2ad to 8.3.x and f783ca2 to 8.2.x. Thanks!Comment #8
alexpottrevisionability is not a word and this is the first instance in our code base. How about:
To detect whether an entity type is revisionable in conditional logic, use EntityTypeInterface::isRevisionable().
Let's add an
@see \Drupal\Core\Entity\EntityTypeInterface::isRevisionable()
and then we can use the short form in the documentation.Comment #9
Wim LeersDone.
P.S.: "revisionable" isn't a word either, yet we use that too. "revisionability" is just the logical extension. Just like "cacheable" and "cacheability".
Comment #10
BerdirWording is a bit repetitive (How would you detect something with non-conditional logic exactly?), but I guess it is hard to avoid that without inventing new words that alex doesn't like :)
Comment #11
xjmHmm I still don't know what exactly "in conditional logic" means. Isn't "conditional logic" redundant?
Maybe an example of what you should or should not do?
Comment #12
tstoecklerMaybe
?
Comment #14
Mile23Try this:
Comment #15
Wim LeersMuch simpler :)
Comment #16
Wim LeersComment #17
catchThis needs a 'why', could be a paraphrase of #4.
Comment #18
Mile23Voila.
Comment #19
Wim LeersComment #20
catchHmm that doesn't cover the main reason for me, which is this:
Comment #21
Mile23Research led to this: #2886622: Deprecate all EntityManager methods with E_USER_DEPRECATED
Comment #22
Mile23How about this?
Comment #25
borisson_That looks like it is a good improvement.
Comment #26
alexpottCommitted and pushed b263f5c4d0 to 8.6.x and 600f720e85 to 8.5.x. Thanks!