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.

CommentFileSizeAuthor
#5 3037247-5.patch2.06 KBamateescu
#2 3037247.patch2.3 KBamateescu

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Postponed
StatusFileSize
new2.3 KB
amateescu’s picture

Status: Postponed » Needs review

The parent issue was committed, we can resume work here :)

Status: Needs review » Needs work

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

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new2.06 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 5: 3037247-5.patch, failed testing. View results

johnwebdev’s picture

+++ b/core/lib/Drupal/Core/Entity/EntityRepository.php
@@ -173,6 +173,16 @@ public function getActiveMultiple($entity_type_id, array $entity_ids, array $con
+    // @todo Use a strict equality check between entity objects once the return
+    //   value of ::getActiveMultiple() is stored in a static cache.
+    //   @see https://www.drupal.org/project/drupal/issues/3031082

Why is a static cache needed to ensure identity right now?

amateescu’s picture

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

johnwebdev’s picture

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

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.