AvatarKitCommonService.php in Avatar Kit 8.2
File
src/Plugin/Derivative/AvatarKitCommonService.php
View source
<?php
namespace Drupal\avatars\Plugin\Derivative;
use dpi\ak\AvatarServiceDiscoveryInterface;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AvatarKitCommonService extends DeriverBase implements ContainerDeriverInterface {
protected $basePluginId;
protected $avatarKitServiceDiscovery;
public function __construct($base_plugin_id, AvatarServiceDiscoveryInterface $avatarKitServiceDiscovery) {
$this->basePluginId = $base_plugin_id;
$this->avatarKitServiceDiscovery = $avatarKitServiceDiscovery;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('avatars.avatar_kit.discovery.services'));
}
public function getDerivativeDefinitions($base_plugin_definition) : array {
$services = $this->avatarKitServiceDiscovery
->getAvatarServices();
foreach ($services as $service) {
$id = $service->id;
$this->derivatives[$id] = $base_plugin_definition;
$this->derivatives[$id]['label'] = $service->name;
$this->derivatives[$id]['description'] = $service->description;
}
return $this->derivatives;
}
}