tarte_au_citron-1.0.0-beta1/src/Plugin/Derivative/TarteAuCitronServiceDeriver.php
src/Plugin/Derivative/TarteAuCitronServiceDeriver.php
<?php
namespace Drupal\tarte_au_citron\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\tarte_au_citron\LibraryJsDiscoverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides service definitions for available services in tac library.
*/
class TarteAuCitronServiceDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* Constructs new FieldBlockDeriver.
*
* @param \Drupal\tarte_au_citron\LibraryJsDiscoverInterface $libraryJsDiscover
* The library js discover service.
*/
public function __construct(protected LibraryJsDiscoverInterface $libraryJsDiscover) {
}
/**
* {@inheritdoc}
*/
public static function create(
ContainerInterface $container,
$base_plugin_id,
): static {
return new static(
$container->get('tarte_au_citron.library_js_discover')
);
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition): array {
$this->derivatives = [];
foreach ($this->libraryJsDiscover->getJsServices() as $serviceKey => $serviceDef) {
$this->derivatives[$serviceKey] = [
'id' => $serviceKey,
'title' => (string) $this->t('@serviceName (From Tarte au citron library services)', ['@serviceName' => $serviceDef['name'] ?? $serviceKey ?? $this->t('Unknown')]),
] + $base_plugin_definition;
if (!empty($serviceDef['params'])) {
$this->derivatives[$serviceKey]['settings'] = $serviceDef['params'];
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
