class Robohash in Avatar Kit 8
Same name in this branch
- 8 avatars_robohash/src/Robohash.php \Drupal\avatars_robohash\Robohash
- 8 avatars_robohash/src/Plugin/AvatarGenerator/Robohash.php \Drupal\avatars_robohash\Plugin\AvatarGenerator\Robohash
Robohash avatar generator.
Plugin annotation
@AvatarGenerator(
id = "robohash",
label = @Translation("Robohash"),
description = @Translation("Robots and monsters from Robohash.org"),
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\avatars_robohash\Plugin\AvatarGenerator\Robohash uses StringTranslationTrait
- class \Drupal\avatars\Plugin\AvatarGenerator\AvatarGeneratorBase implements AvatarGeneratorPluginInterface
Expanded class hierarchy of Robohash
2 string references to 'Robohash'
- avatars_robohash.info.yml in avatars_robohash/
avatars_robohash.info.yml - avatars_robohash/avatars_robohash.info.yml
- avatars_robohash.schema.yml in avatars_robohash/
config/ schema/ avatars_robohash.schema.yml - avatars_robohash/config/schema/avatars_robohash.schema.yml
File
- avatars_robohash/
src/ Plugin/ AvatarGenerator/ Robohash.php, line 23
Namespace
Drupal\avatars_robohash\Plugin\AvatarGeneratorView source
class Robohash extends AvatarGeneratorBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'type' => '',
'background' => '',
];
}
/**
* {@inheritdoc}
*/
public function generateUri(AccountInterface $account) {
$robohash = new RobohashAPI();
$type_map = [
'robots' => 'robot',
'robot_heads' => 'robot_head',
'monsters' => 'monster',
];
$type = $this->configuration['type'];
$background_map = [
'transparent' => 'transparent',
'background_1' => 'places',
'background_2' => 'patterns',
];
$background = $this->configuration['background'];
return $robohash
->setIdentifier($this
->getIdentifier($account))
->setType(isset($type_map[$type]) ? $type_map[$type] : '')
->setBackground(isset($background_map[$background]) ? $background_map[$background] : '')
->getUrl();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['type'] = [
'#type' => 'radios',
'#title' => $this
->t('Type'),
'#options' => [
'robots' => $this
->t('Robots'),
'robot_heads' => $this
->t('Robot Heads'),
'monsters' => $this
->t('Monsters'),
],
'#default_value' => $this->configuration['type'],
];
$form['background'] = [
'#type' => 'radios',
'#title' => $this
->t('Background'),
'#options' => [
'transparent' => $this
->t('Transparent'),
'background_1' => $this
->t('Places'),
'background_2' => $this
->t('Patterns'),
],
'#empty_value' => '',
'#default_value' => $this->configuration['background'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['type'] = $form_state
->getValue('type');
$this->configuration['background'] = $form_state
->getValue('background');
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
if (empty($this->configuration['type']) || empty($this->configuration['background'])) {
$summary[] = $this
->t('Missing Configuration');
}
else {
$summary[]['#markup'] = $this
->t('Type: @type | Background: @background', [
'@type' => $this->configuration['type'],
'@background' => $this->configuration['background'],
]);
}
return $summary;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AvatarGeneratorBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
AvatarGeneratorBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
AvatarGeneratorBase:: |
public | function |
Gets File object for an avatar. Overrides AvatarGeneratorPluginInterface:: |
1 |
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 |
Form validation handler. Overrides PluginFormInterface:: |
|
AvatarGeneratorBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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. | |
Robohash:: |
public | function |
Form constructor. Overrides AvatarGeneratorBase:: |
|
Robohash:: |
public | function |
Gets default configuration for this plugin. Overrides AvatarGeneratorBase:: |
|
Robohash:: |
public | function |
Creates a URI to an avatar. Overrides AvatarGeneratorBase:: |
|
Robohash:: |
public | function |
Generate a summary about the current configuration of the widget. Overrides AvatarGeneratorBase:: |
|
Robohash:: |
public | function |
Form submission handler. Overrides AvatarGeneratorBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |