class LetterAvatar in Letter Avatar 8
Gravatar avatar generator.
Plugin annotation
@AvatarGenerator(
id = "letter_avatar",
label = @Translation("Letter Avatar"),
description = @Translation("Letter generated by the LetterAvatar library."),
fallback = TRUE,
dynamic = FALSE,
remote = TRUE
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\avatars\Plugin\AvatarGenerator\AvatarGeneratorBase implements AvatarGeneratorPluginInterface
- class \Drupal\letter_avatar\Plugin\AvatarGenerator\LetterAvatar
- class \Drupal\avatars\Plugin\AvatarGenerator\AvatarGeneratorBase implements AvatarGeneratorPluginInterface
Expanded class hierarchy of LetterAvatar
File
- src/
Plugin/ AvatarGenerator/ LetterAvatar.php, line 27 - Contains \Drupal\letter_avatar\Plugin\AvatarGenerator\LetterAvatar.
Namespace
Drupal\letter_avatar\Plugin\AvatarGeneratorView source
class LetterAvatar extends AvatarGeneratorBase {
/**
* {@inheritdoc}
*/
public function getFile(AccountInterface $account) {
$directory = 'public://avatar_kit/ak_letter';
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$letter = mb_substr($account
->getUsername(), 0, 1);
$path = $directory . '/' . $account
->id() . '.png';
// todo: update existing file entity
// if you update a file on the file system directly, page caches and image
// styles will not flush.
$ids = \Drupal::entityManager()
->getStorage('file')
->getQuery()
->condition('uri', $path)
->execute();
if ($id = reset($ids)) {
$file = File::load($id);
$file
->delete();
}
$letterAvatar = new LetterAvatarAPI();
$letterAvatar
->generate($letter, 256)
->saveAsPng($file_system
->realpath($path));
// File cannot chain methods.
$file = File::create();
$file
->setFileUri($path);
$file
->setOwnerId($account
->id());
// Temporary until AvatarPreview adds usage.
$file
->setTemporary();
return $file;
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AvatarGeneratorBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
3 |
AvatarGeneratorBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
AvatarGeneratorBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
3 |
AvatarGeneratorBase:: |
public | function |
Creates a URI to an avatar. Overrides AvatarGeneratorPluginInterface:: |
8 |
AvatarGeneratorBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
AvatarGeneratorBase:: |
protected | function | Create a site-unique identifier for a user. | |
AvatarGeneratorBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
AvatarGeneratorBase:: |
public | function |
Generate a summary about the current configuration of the widget. Overrides AvatarGeneratorPluginInterface:: |
3 |
AvatarGeneratorBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
AvatarGeneratorBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
AvatarGeneratorBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
LetterAvatar:: |
public | function |
Gets File object for an avatar. Overrides AvatarGeneratorBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |