\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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

dawehner’s picture

Well, 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 :)

Berdir’s picture

Title: UserInterface + FileInterface + MenuLinkContentInterface + … should not extend \Drupal\Core\Entity\ContentEntityInterface, because it does not support revisions » Document why UserInterface + FileInterface + MenuLinkContentInterface + … extend \Drupal\Core\Entity\ContentEntityInterface
Category: Bug report » Task
Priority: Major » Minor

Yeah, 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)

Wim Leers’s picture

Status: Active » Needs review
Issue tags: +Documentation
FileSize
849 bytes
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you wim! I hope this clarifies the situation up.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 481a2ad to 8.3.x and f783ca2 to 8.2.x. Thanks!

alexpott’s picture

Status: Fixed » Needs work
  1. This looks helpful - nice docs. However, I ended up not committing because there are some simple improvements we can do.
  2. +++ b/core/lib/Drupal/Core/Entity/RevisionableInterface.php
    @@ -4,6 +4,12 @@
    + * revisionability in conditional logic, use
    

    revisionability 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().

  3. +++ b/core/lib/Drupal/Core/Entity/RevisionableInterface.php
    @@ -4,6 +4,12 @@
    + * \Drupal\Core\Entity\EntityTypeInterface::isRevisionable().
    

    Let's add an @see \Drupal\Core\Entity\EntityTypeInterface::isRevisionable() and then we can use the short form in the documentation.

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
925 bytes
980 bytes

Done.

P.S.: "revisionable" isn't a word either, yet we use that too. "revisionability" is just the logical extension. Just like "cacheable" and "cacheability".

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Wording 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 :)

xjm’s picture

Status: Reviewed & tested by the community » Needs review

Hmm 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?

tstoeckler’s picture

Maybe

You MUST NOT use this interface in instanceof checks...

?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Try this:

/**
 * Provides methods for an entity to support revisions.
 *
 * Classes implementing this interface do not necessarily support revisions.
 *
 * To detect whether an entity type supports revisions, call
 * EntityTypeInterface::isRevisionable().
 *
 * @see \Drupal\Core\Entity\EntityTypeInterface::isRevisionable()
 */
interface RevisionableInterface {
Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Much simpler :)

Wim Leers’s picture

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Entity/RevisionableInterface.php
@@ -4,6 +4,13 @@
+ *
+ * Classes implementing this interface do not necessarily support revisions.
+ *
+ * To detect whether an entity type supports revisions, call
+ * EntityTypeInterface::isRevisionable().
+ *
+ * @see \Drupal\Core\Entity\EntityTypeInterface::isRevisionable()
  */
 interface RevisionableInterface {

This needs a 'why', could be a paraphrase of #4.

Mile23’s picture

Status: Needs work » Needs review
FileSize
2.53 KB
2.38 KB

Voila.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Needs work

Hmm that doesn't cover the main reason for me, which is this:

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.

Mile23’s picture

Mile23’s picture

Status: Needs work » Needs review
FileSize
5.15 KB
5.47 KB

How about this?

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

That looks like it is a good improvement.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed b263f5c4d0 to 8.6.x and 600f720e85 to 8.5.x. Thanks!

  • alexpott committed b263f5c on 8.6.x
    Issue #2822611 by Mile23, Wim Leers, alexpott, Berdir, catch, dawehner,...

  • alexpott committed 600f720 on 8.5.x
    Issue #2822611 by Mile23, Wim Leers, alexpott, Berdir, catch, dawehner,...

Status: Fixed » Closed (fixed)

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