You are here

abstract class AvatarGeneratorBase in Avatar Kit 8

AvatarGenerator plugin base class.

Hierarchy

Expanded class hierarchy of AvatarGeneratorBase

6 files declare their use of AvatarGeneratorBase
Adorable.php in avatars_adorable/src/Plugin/AvatarGenerator/Adorable.php
DynamicTestGenerator.php in tests/modules/avatars_test/src/Plugin/AvatarGenerator/DynamicTestGenerator.php
Gravatar.php in avatars_gravatar/src/Plugin/AvatarGenerator/Gravatar.php
GravatarGenerator.php in avatars_gravatar/src/Plugin/AvatarGenerator/GravatarGenerator.php
Robohash.php in avatars_robohash/src/Plugin/AvatarGenerator/Robohash.php

... See full list

File

src/Plugin/AvatarGenerator/AvatarGeneratorBase.php, line 12

Namespace

Drupal\avatars\Plugin\AvatarGenerator
View source
abstract class AvatarGeneratorBase extends PluginBase implements AvatarGeneratorPluginInterface {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configuration = array_merge($this
      ->defaultConfiguration(), $this->configuration);
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * Create a site-unique identifier for a user.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   A user account.
   *
   * @return string
   *   A unique string based on the user.
   */
  protected function getIdentifier(AccountInterface $account) {

    // There is no ID for new users (registration page).
    if ($account
      ->isNew()) {
      return '0';
    }
    else {
      return !empty($account
        ->getEmail()) ? $account
        ->getEmail() : (string) $account
        ->id();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getFile(AccountInterface $account) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function generateUri(AccountInterface $account) {
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AvatarGeneratorBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 3
AvatarGeneratorBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
AvatarGeneratorBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 3
AvatarGeneratorBase::generateUri public function Creates a URI to an avatar. Overrides AvatarGeneratorPluginInterface::generateUri 8
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::settingsSummary public function Generate a summary about the current configuration of the widget. Overrides AvatarGeneratorPluginInterface::settingsSummary 3
AvatarGeneratorBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 3
AvatarGeneratorBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
AvatarGeneratorBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
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.