Provides some handy extra cache tags, so you can for example tag a block that deals with a certain node type, with the cache tag of that node type.

The module provides the following cache tags for you to use:

handy_cache_tags:[entity_type]
handy_cache_tags:[entity_type]:[entity_bundle]

For example with nodes of the bundle "article" this would make the following cache tags available:

handy_cache_tags:node
handy_cache_tags:node:article

The first would invalidate on any node (which by coincidence also is provided through the "node_list" cache tag in core). The second would invalidate on any node being created, updated or deleted with the bundle article.

To generate these tags for your render array, you can use the following:

$build['#cache'] = [
  'tags' => [
    // This one generates the bundle specific cache tag.
    \Drupal::service('handy_cache_tags.manager')->getBundleTag('node', 'article'),
    // This one generates the entity type cache tag.
    \Drupal::service('handy_cache_tags.manager')->getTag('node'),
  ],
];

If your render array deals with an entity, you can also use the following helper functions:

// Get all tags for an entity:
\Drupal::service('handy_cache_tags.manager')
  ->getEntityTags(EntityInterface $entity);

// Get entity type tag from an entity:
\Drupal::service('handy_cache_tags.manager')
  ->getEntityTypeTagFromEntity(EntityInterface $entity);

// Get bundle tag from entity:
\Drupal::service('handy_cache_tags.manager')
  ->getBundleTagFromEntity(EntityInterface $entity);
Supporting organizations: 
Development and maintenance

Project information

Releases