Introduce EntityBase::getCacheTagsToInvalidateOnSave()

Created on 24 July 2019, over 5 years ago
Updated 4 February 2024, 11 months ago

Problem/Motivation

In our use-case we overwrite EntityBase::invalidateTagsOnSave(), but we need to copy most of the original method, because we still want to get the cache tag of the entity like core does.

Proposed resolution

Add EntityBase::getCacheTagsToInvalidateOnSave and EntityBase::getTagsToInvalidateOnDelete() which will be used by the methods ::invalidateTagsOnSave() and ::invalidateTagsOnDelete() when saving or deleting an entity respectfully.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Feature request
Status

Needs work

Version

11.0 🔥

Component
Entity 

Last updated about 17 hours ago

Created by

🇩🇪Germany kfritsche 🇩🇪🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review almost 2 years ago
  • 🇫🇮Finland sokru

    Reroll and removed unused use statement.

  • 🇫🇮Finland lauriii Finland

    Added a draft change record.

  • Status changed to RTBC almost 2 years ago
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    Change record looks super clear, thanks @lauriii!

    • catch committed 7e847dc5 on 10.1.x
      Issue #3070022 by gease, sokru, kfritsche, hchonov, lauriii: Introduce...
  • Status changed to Fixed almost 2 years ago
  • 🇬🇧United Kingdom catch

    Committed/pushed to 10.1.x, thanks!

  • 🇧🇪Belgium dieterholvoet Brussels

    Is there a reason for the naming inconsistency between getCacheTagsToInvalidateOnSave and getTagsToInvalidateOnDelete? Why not getCacheTagsToInvalidateOnDelete?

  • 🇨🇭Switzerland berdir Switzerland
    +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
    @@ -490,12 +489,8 @@ protected function invalidateTagsOnSave($update) {
        */
    -  protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) {
    -    $tags = $entity_type->getListCacheTags();
    -    foreach ($entities as $entity) {
    -      $tags = Cache::mergeTags($tags, $entity->getListCacheTagsToInvalidate());
    -    }
    -    Cache::invalidateTags($tags);
    +  protected static function getTagsToInvalidateOnDelete(EntityTypeInterface $entity_type, array $entities) {
    +    return $entity_type->getListCacheTags();
       }
    

    this dropped the call to $entity->getListCacheTagsToInvalidate(). This happened between #21 and #26, where that call was introduced in HEAD, but the reroll dropped it. I don't think it was deliberate.

    Since there are no config entities with bundles, there are no failing tests, but there's still a possibility that someone implemented that method and that no longer works correctly now?

    Tags vs CacheTags is a bit inconsistent indeed, but the existing/replaced methods also used just Tags and not CacheTags, so I think that's fine.

    • catch committed 02f06bc2 on 10.1.x
      Revert "Issue #3070022 by gease, sokru, kfritsche, hchonov, lauriii:...
  • Status changed to Needs work almost 2 years ago
  • 🇬🇧United Kingdom catch

    Agreed with both points from #39 (although config entities with bundles is a terrifying idea). Rolling back so we can re-commit with the extra getListCacheTagsToInvalidate() and I think if we want to address the method naming mismatch that could happen in a follow-up to deprecate the old methods and add new ones.

  • Status changed to Needs review almost 2 years ago
  • 🇧🇷Brazil murilohp

    Just made a new reroll and now the getListCacheTagsToInvalidate is back. Moving back to NR.

  • Status changed to RTBC almost 2 years ago
  • 🇬🇧United Kingdom catch

    That looks great. Since I already committed without this, moving back to RTBC, and I'll commit in a couple of days if no further comments.

  • 🇨🇭Switzerland berdir Switzerland

    FWIW, I don't think this implements what the original proposal was, which said a single shared method between the two? The fact that it's still two separate methods *and* that there doesn't seem to be a use case in core to override this makes me question a bit how useful this really is?

  • Status changed to Needs work almost 2 years ago
  • 🇩🇪Germany tobiasb Berlin

    Change CR back again to draft.

Production build 0.71.5 2024