Problem/Motivation

Entities are providing the \Drupal\Core\Entity\EntityBase::getListCacheTagsToInvalidate() method which are used to invalidate tags when saving and deleting entities.
It would be nice to be able to add the tags returned by this method to the ones the module are already invalidating.

Proposed resolution

Either add a global setting to also invalidate list cache tags when using the local actions.
Or provide a way to decide every time the action is used (this could be another link or a confirm form).

Remaining tasks

Decide the way to do it.
Implement.

User interface changes

To be defined.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

duaelfr created an issue. See original summary.

duaelfr’s picture

For the time being, I will implement hook_entity_cache_rebuild_alter to add the tags I need but please consider adding this to the module.
What would be your choice between the proposed implementations?

duaelfr’s picture

FWIW, here is how I implemented it:

namespace Drupal\mymodule\Hook;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityInterface;

class MyModuleHooks {

  #[Hook('entity_cache_rebuild_alter')]
  public function addListCacheTagsToInvalidateForEntityCacheRebuild(array &$cache_tags, &$message, ContentEntityInterface $entity) {
    $entityType = $entity->getEntityType();
    $cache_tags = Cache::mergeTags($cache_tags, $entityType->getListCacheTags());
    if ($entityType->hasKey('bundle')) {
      $cache_tags = Cache::mergeTags($cache_tags, $entityType->getBundleListCacheTags($entity->bundle()));
    }
  }

}
efpapado’s picture

I think we could add it directly to the controller, it makes sense that all relevant cache tags should be invalidated. Do you want to implement this yourself?

duaelfr’s picture

Status: Active » Needs review

Done :)

efpapado’s picture

Status: Needs review » Fixed

Merged :)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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