You are here

class AvatarKitCommonService in Avatar Kit 8.2

Same name in this branch
  1. 8.2 src/Plugin/Derivative/AvatarKitCommonService.php \Drupal\avatars\Plugin\Derivative\AvatarKitCommonService
  2. 8.2 src/Plugin/Avatars/Service/AvatarKitCommonService.php \Drupal\avatars\Plugin\Avatars\Service\AvatarKitCommonService

Creates services for each Avatar Kit library service.

Hierarchy

Expanded class hierarchy of AvatarKitCommonService

File

src/Plugin/Derivative/AvatarKitCommonService.php, line 13

Namespace

Drupal\avatars\Plugin\Derivative
View source
class AvatarKitCommonService extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The base plugin ID this derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * Avatar Kit service discovery.
   *
   * @var \dpi\ak\AvatarServiceDiscoveryInterface
   */
  protected $avatarKitServiceDiscovery;

  /**
   * Constructs an EntityDeriver object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \dpi\ak\AvatarServiceDiscoveryInterface $avatarKitServiceDiscovery
   *   Avatar Kit service discovery.
   */
  public function __construct($base_plugin_id, AvatarServiceDiscoveryInterface $avatarKitServiceDiscovery) {
    $this->basePluginId = $base_plugin_id;
    $this->avatarKitServiceDiscovery = $avatarKitServiceDiscovery;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container
      ->get('avatars.avatar_kit.discovery.services'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AvatarKitCommonService::$avatarKitServiceDiscovery protected property Avatar Kit service discovery.
AvatarKitCommonService::$basePluginId protected property The base plugin ID this derivative is for.
AvatarKitCommonService::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
AvatarKitCommonService::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
AvatarKitCommonService::__construct public function Constructs an EntityDeriver object.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition