You are here

public function AvatarManager::getAvatarPreviewByFile in Avatar Kit 8

Determines if a file entity is an avatar preview.

Parameters

\Drupal\file\FileInterface $file: The file entity to check.

Return value

int|false Returns the avatar preview entity ID, or FALSE if the file is not a avatar preview.

Overrides AvatarManagerInterface::getAvatarPreviewByFile

File

src/AvatarManager.php, line 296

Class

AvatarManager
Provides an avatar manager service.

Namespace

Drupal\avatars

Code

public function getAvatarPreviewByFile(FileInterface $file) {
  $usages = $this->fileUsage
    ->listUsage($file);
  if (isset($usages['avatars']['avatars_preview'])) {
    $avatar_previews = array_keys($usages['avatars']['avatars_preview']);

    // Return the first key, there should only ever be one.
    return reset($avatar_previews);
  }
  return FALSE;
}