You are here

function avatars_file_storage_load in Avatar Kit 8

Implements hook_ENTITY_TYPE_storage_load().

Add cache tags to avatar preview files. These tags will be added when image formatters are rendered.

File

./avatars.module, line 142

Code

function avatars_file_storage_load(array $entities) {

  /** @var $entities \Drupal\file\FileInterface[] */

  /** @var \Drupal\avatars\AvatarManager $avatar_manager */
  $avatar_manager = \Drupal::service('avatars.avatar_manager');
  foreach ($entities as $file) {
    if (FALSE !== $avatar_manager
      ->getAvatarPreviewByFile($file)) {
      $file
        ->addCacheTags([
        'avatar_preview',
      ]);
    }
  }
}