You are here

class HandyCacheTagsManager in Handy cache tags 8

HandyCacheTagsManager service.

Hierarchy

Expanded class hierarchy of HandyCacheTagsManager

2 files declare their use of HandyCacheTagsManager
HandyCacheTagsBase.php in tests/src/Unit/HandyCacheTagsBase.php
TagNamesTest.php in tests/src/Unit/TagNamesTest.php
1 string reference to 'HandyCacheTagsManager'
handy_cache_tags.services.yml in ./handy_cache_tags.services.yml
handy_cache_tags.services.yml
1 service uses HandyCacheTagsManager
handy_cache_tags.manager in ./handy_cache_tags.services.yml
Drupal\handy_cache_tags\HandyCacheTagsManager

File

src/HandyCacheTagsManager.php, line 10

Namespace

Drupal\handy_cache_tags
View source
class HandyCacheTagsManager {

  /**
   * The cache prefix we use for all cache tags.
   */
  const CACHE_PREFIX = 'handy_cache_tags';

  /**
   * Creates cache tags from entities.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   An entity to use.
   *
   * @return array
   *   Array of cache tags.
   */
  public function getEntityTags(EntityInterface $entity) {
    return [
      $this
        ->getEntityTypeTagFromEntity($entity),
      $this
        ->getBundleTagFromEntity($entity),
    ];
  }

  /**
   * Gets entity type tags from the entity.
   */
  public function getEntityTypeTagFromEntity(EntityInterface $entity) {
    return $this
      ->getTag($entity
      ->getEntityTypeId());
  }

  /**
   * Gets a tag from a string.
   */
  public function getTag($type) {
    return sprintf('%s:%s', $this::CACHE_PREFIX, $type);
  }

  /**
   * Gets bundle tag for an entity.
   */
  public function getBundleTagFromEntity(EntityInterface $entity) {
    return $this
      ->getBundleTag($entity
      ->getEntityTypeId(), $entity
      ->bundle());
  }

  /**
   * Gets a bundle tag from a type and a bundle.
   */
  public function getBundleTag($entity_type, $bundle) {
    return $this
      ->getTag(sprintf('%s:%s', $entity_type, $bundle));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HandyCacheTagsManager::CACHE_PREFIX constant The cache prefix we use for all cache tags.
HandyCacheTagsManager::getBundleTag public function Gets a bundle tag from a type and a bundle.
HandyCacheTagsManager::getBundleTagFromEntity public function Gets bundle tag for an entity.
HandyCacheTagsManager::getEntityTags public function Creates cache tags from entities.
HandyCacheTagsManager::getEntityTypeTagFromEntity public function Gets entity type tags from the entity.
HandyCacheTagsManager::getTag public function Gets a tag from a string.