abstract class AvatarKitCommonService in Avatar Kit 8.2
Same name in this branch
- 8.2 src/Plugin/Derivative/AvatarKitCommonService.php \Drupal\avatars\Plugin\Derivative\AvatarKitCommonService
- 8.2 src/Plugin/Avatars/Service/AvatarKitCommonService.php \Drupal\avatars\Plugin\Avatars\Service\AvatarKitCommonService
Automatically creates services based on plugins from Avatar Kit library.
Plugin annotation
@AvatarKitService(
id = "avatars_ak_common",
deriver = "Drupal\avatars\Plugin\Derivative\AvatarKitCommonService"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\avatars\Plugin\Avatars\Service\AvatarKitServiceBase implements AvatarKitServiceInterface
- class \Drupal\avatars\Plugin\Avatars\Service\AvatarKitCommonService implements ContainerFactoryPluginInterface uses StringTranslationTrait
- class \Drupal\avatars\Plugin\Avatars\Service\AvatarKitServiceBase implements AvatarKitServiceInterface
Expanded class hierarchy of AvatarKitCommonService
File
- src/
Plugin/ Avatars/ Service/ AvatarKitCommonService.php, line 25
Namespace
Drupal\avatars\Plugin\Avatars\ServiceView source
abstract class AvatarKitCommonService extends AvatarKitServiceBase implements ContainerFactoryPluginInterface {
/**
* Avatar Kit service discovery.
*
* @var \dpi\ak\AvatarServiceDiscoveryInterface
*/
protected $avatarKitServiceDiscovery;
/**
* Avatar Kit service factory.
*
* @var \dpi\ak\AvatarServiceFactoryInterface
*/
protected $avatarKitServiceFactory;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AvatarServiceDiscoveryInterface $avatarKitServiceDiscovery, AvatarServiceFactoryInterface $avatarKitServiceFactory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->avatarKitServiceDiscovery = $avatarKitServiceDiscovery;
$this->avatarKitServiceFactory = $avatarKitServiceFactory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('avatars.avatar_kit.discovery.services'), $container
->get('avatars.avatar_kit.factory.services'));
}
use StringTranslationTrait;
/**
* Creates a service from Avatar Kit library.
*
* @param \dpi\ak\AvatarConfigurationInterface $configuration
* Avatar service configuration.
*
* @return \dpi\ak\AvatarKit\AvatarServices\AvatarServiceInterface
* A new service instance
*/
protected function createService(AvatarConfigurationInterface $configuration) : AvatarServiceInterface {
$id = $this
->getDerivativeId();
return $this->avatarKitServiceFactory
->createService($id, $configuration);
}
/**
* Create a new configuration object.
*
* @return \dpi\ak\AvatarConfigurationInterface
* A new configuration object.
*/
protected function newAvatarConfiguration() : AvatarConfigurationInterface {
return new AvatarConfiguration();
}
/**
* Gets metadata for a service from Avatar Kit library.
*
* @return \dpi\ak\Annotation\AvatarService
* Metadata for a service from Avatar Kit library.
*/
protected function getMetadata() : AvatarService {
$id = $this
->getDerivativeId();
return $this->avatarKitServiceDiscovery
->getMetadata($id);
}
/**
* Create a service instance.
*
* @return \dpi\ak\AvatarKit\AvatarServices\AvatarServiceInterface
* A new service instance
*/
protected function getService() {
$configuration = $this
->newAvatarConfiguration();
$width = $this->configuration['width'] ?? NULL;
if (is_int($width)) {
$configuration
->setWidth($width);
}
$height = $this->configuration['height'] ?? NULL;
if (is_int($height)) {
$configuration
->setHeight($height);
}
$protocol = $this->configuration['protocol'] ?? NULL;
if (!empty($protocol)) {
$configuration
->setProtocol($protocol);
}
return $this
->createService($configuration);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) : array {
$metadata = $this
->getMetadata();
$protocols = $metadata->protocols ?? [];
$protocol_options = array_combine($protocols, $protocols);
$form['protocol'] = [
'#title' => $this
->t('Protocol'),
'#options' => $protocol_options,
'#default_value' => $this->configuration['protocol'] ?? NULL,
'#required' => TRUE,
'#type' => 'select',
];
$form['width'] = [
'#title' => $this
->t('Source width'),
'#type' => 'number',
'#default_value' => $this->configuration['width'] ?? NULL,
];
$form['height'] = [
'#title' => $this
->t('Source height'),
'#type' => 'number',
'#default_value' => $this->configuration['height'] ?? NULL,
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) : void {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['width'] = $form_state
->getValue('width');
$this->configuration['height'] = $form_state
->getValue('height');
$this->configuration['protocol'] = $form_state
->getValue('protocol');
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() : array {
$configuration = parent::defaultConfiguration();
$configuration['width'] = NULL;
$configuration['height'] = NULL;
$configuration['protocol'] = NULL;
return $configuration;
}
/**
* {@inheritdoc}
*/
public function getAvatar(AvatarIdentifierInterface $identifier) : ?string {
return $this
->getService()
->getAvatar($identifier);
}
/**
* {@inheritdoc}
*/
public function createIdentifier() : AvatarIdentifierInterface {
return $this
->getService()
->createIdentifier();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AvatarKitCommonService:: |
protected | property | Avatar Kit service discovery. | |
AvatarKitCommonService:: |
protected | property | Avatar Kit service factory. | |
AvatarKitCommonService:: |
public | function |
Form constructor. Overrides AvatarKitServiceBase:: |
|
AvatarKitCommonService:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AvatarKitCommonService:: |
public | function |
Overrides AvatarKitServiceBase:: |
|
AvatarKitCommonService:: |
protected | function | Creates a service from Avatar Kit library. | |
AvatarKitCommonService:: |
public | function |
Gets default configuration for this plugin. Overrides AvatarKitServiceBase:: |
|
AvatarKitCommonService:: |
public | function | ||
AvatarKitCommonService:: |
protected | function | Gets metadata for a service from Avatar Kit library. | |
AvatarKitCommonService:: |
protected | function | Create a service instance. | |
AvatarKitCommonService:: |
protected | function | Create a new configuration object. | |
AvatarKitCommonService:: |
public | function |
Form submission handler. Overrides AvatarKitServiceBase:: |
|
AvatarKitCommonService:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
AvatarKitServiceBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
AvatarKitServiceBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
|
AvatarKitServiceBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
|
AvatarKitServiceBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
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. | |
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. |