You are here

User.php in Avatar Kit 8

File

src/Plugin/AvatarGenerator/User.php
View source
<?php

namespace Drupal\avatars\Plugin\AvatarGenerator;

use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\User as CoreUser;

/**
 * User plugin.
 *
 * @AvatarGenerator(
 *   id = "user",
 *   label = @Translation("User upload"),
 *   description = @Translation("Image uploaded by the user to the site."),
 *   dynamic = TRUE,
 *   fallback = FALSE,
 *   remote = FALSE
 * )
 */
class User extends AvatarGeneratorBase {

  /**
   * {@inheritdoc}
   */
  public function getFile(AccountInterface $account) {
    if (!$account
      ->isAnonymous() && ($user = CoreUser::load($account
      ->id()))) {
      $entities = $user->{AK_FIELD_PICTURE_USER}
        ->referencedEntities();
      return reset($entities);
    }
    return NULL;
  }

}

Classes

Namesort descending Description
User User plugin.