You are here

class GravatarGenerator in Avatar Kit 8

Gravatar generated avatars generator.

Plugin annotation


@AvatarGenerator(
  id = "gravatar_generator",
  label = @Translation("Gravatar generator"),
  description = @Translation("Identicon, MonsterID, Retro, and Wavatar avatar generators."),
  fallback = TRUE,
  dynamic = FALSE,
  remote = TRUE
)

Hierarchy

Expanded class hierarchy of GravatarGenerator

File

avatars_gravatar/src/Plugin/AvatarGenerator/GravatarGenerator.php, line 23

Namespace

Drupal\avatars_gravatar\Plugin\AvatarGenerator
View source
class GravatarGenerator extends AvatarGeneratorBase {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'type' => '',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function generateUri(AccountInterface $account) {
    $gravatar = new GravatarAPI();
    return $gravatar
      ->setIdentifier($this
      ->getIdentifier($account))
      ->setType($this->configuration['type'])
      ->setDimensions(256)
      ->getUrl();
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['type'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Type'),
      '#options' => [
        'identicon' => $this
          ->t('Identicon'),
        'monsterid' => $this
          ->t('Monster ID'),
        'wavatar' => $this
          ->t('Wavatar'),
        'retro' => $this
          ->t('8-bit style avatar'),
      ],
      '#default_value' => $this->configuration['type'],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['type'] = $form_state
      ->getValue('type');
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    $summary = [];
    if (empty($this->configuration['type'])) {
      $summary[] = $this
        ->t('Missing Configuration');
    }
    else {
      $summary[]['#markup'] = $this
        ->t('Type: @type', [
        '@type' => $this->configuration['type'],
      ]);
    }
    return $summary;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AvatarGeneratorBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
AvatarGeneratorBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
AvatarGeneratorBase::getFile public function Gets File object for an avatar. Overrides AvatarGeneratorPluginInterface::getFile 1
AvatarGeneratorBase::getIdentifier protected function Create a site-unique identifier for a user.
AvatarGeneratorBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
AvatarGeneratorBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
AvatarGeneratorBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
GravatarGenerator::buildConfigurationForm public function Form constructor. Overrides AvatarGeneratorBase::buildConfigurationForm
GravatarGenerator::defaultConfiguration public function Gets default configuration for this plugin. Overrides AvatarGeneratorBase::defaultConfiguration
GravatarGenerator::generateUri public function Creates a URI to an avatar. Overrides AvatarGeneratorBase::generateUri
GravatarGenerator::settingsSummary public function Generate a summary about the current configuration of the widget. Overrides AvatarGeneratorBase::settingsSummary
GravatarGenerator::submitConfigurationForm public function Form submission handler. Overrides AvatarGeneratorBase::submitConfigurationForm
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.