You are here

function avatars_callback_avatar_generators in Avatar Kit 8

To be consumed by field AK_FIELD_AVATAR_GENERATOR allowed_values_function.

Implements callback_allowed_values_function().

Return value

string[int]

1 string reference to 'avatars_callback_avatar_generators'
field.storage.user.avatars_avatar_generator.yml in config/install/field.storage.user.avatars_avatar_generator.yml
config/install/field.storage.user.avatars_avatar_generator.yml

File

./avatars.module, line 193

Code

function avatars_callback_avatar_generators(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = TRUE) {

  // @todo remove this, add update hook for existing field form displays.

  /** @var \Drupal\avatars\AvatarGeneratorStorageInterface $avatars_generator_storage */
  $avatars_generator_storage = \Drupal::entityTypeManager()
    ->getStorage('avatar_generator');
  $options = [
    '_none' => t('Site default'),
  ];
  foreach ($avatars_generator_storage
    ->getEnabledAvatarGenerators() as $instance) {
    if ($instance
      ->getPlugin()
      ->getPluginId() == 'user_preference') {
      continue;
    }
    if ($entity instanceof UserInterface) {
      $options[$instance
        ->id()] = $instance
        ->label();
    }
  }
  return $options;
}