AvatarKitServicePluginManager.php in Avatar Kit 8.2
File
src/AvatarKitServicePluginManager.php
View source
<?php
namespace Drupal\avatars;
use Drupal\avatars\Annotation\AvatarKitService;
use Drupal\avatars\Event\AvatarKitEvents;
use Drupal\avatars\Event\AvatarKitServiceDefinitionAlterEvent;
use Drupal\avatars\Plugin\Avatars\Service\AvatarKitServiceInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class AvatarKitServicePluginManager extends DefaultPluginManager implements AvatarKitServicePluginManagerInterface {
protected $eventDispatcher;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EventDispatcherInterface $eventDispatcher) {
parent::__construct('Plugin/Avatars/Service', $namespaces, $module_handler, AvatarKitServiceInterface::class, AvatarKitService::class);
$this
->setCacheBackend($cache_backend, 'avatar_service_plugins');
$this->eventDispatcher = $eventDispatcher;
}
protected function findDefinitions() : array {
$definitions = parent::findDefinitions();
$definitions = array_filter($definitions, function (array $definition) : bool {
$class = $definition['class'] ?? '';
try {
$reflection = new \ReflectionClass($class);
return !$reflection
->isAbstract();
} catch (\ReflectionException $e) {
}
return FALSE;
});
return $definitions;
}
protected function alterDefinitions(&$definitions) {
$event = (new AvatarKitServiceDefinitionAlterEvent())
->setDefinitions($definitions);
$event = $this->eventDispatcher
->dispatch(AvatarKitEvents::PLUGIN_SERVICE_ALTER, $event);
$definitions = $event
->getDefinitions();
}
}