You are here

public function AvatarKitEntityFieldHandler::copyCacheToEntity in Avatar Kit 8.2

Copies the avatar in a cache entity to an entity.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: A entity.

\Drupal\avatars\Entity\AvatarCacheInterface $avatar_cache: An avatar cache entity.

Overrides AvatarKitEntityFieldHandlerInterface::copyCacheToEntity

1 call to AvatarKitEntityFieldHandler::copyCacheToEntity()
AvatarKitEntityFieldHandler::checkUpdates in src/AvatarKitEntityFieldHandler.php
Checks if there are updates to the first avatar for an entity.

File

src/AvatarKitEntityFieldHandler.php, line 38

Class

AvatarKitEntityFieldHandler
Handles pushing avatar caches into entities.

Namespace

Drupal\avatars

Code

public function copyCacheToEntity(FieldableEntityInterface $entity, AvatarCacheInterface $avatar_cache) : void {
  $field_name = $this
    ->getAvatarFieldName($entity);
  if (!$field_name) {
    throw new \Exception('Entity does not accept avatars.');
  }
  $file = $avatar_cache
    ->getAvatar();
  $this
    ->pushFileIntoEntity($entity, $field_name, $file);
}