devel_wizard-2.x-dev/templates/spell/entity_type_group/plugin-group-relation-deriver.php.twig
templates/spell/entity_type_group/plugin-group-relation-deriver.php.twig
<?php
declare(strict_types=1);
namespace Drupal\{{ module.machineName }}\Plugin\Group\Relation;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\group\Plugin\Group\Relation\GroupRelationTypeInterface;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class {{ groupRelationPlugin.deriverClass }} extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$base_plugin_id,
$container->get('entity_type.manager'),
$container->get('string_translation'),
);
}
public function __construct(
protected string $basePluginId,
protected EntityTypeManagerInterface $entityTypeManager,
TranslationInterface $translation,
) {
$this->setStringTranslation($translation);
}
/**
* {@inheritdoc}.
*/
public function getDerivativeDefinitions($base_plugin_definition) {
assert($base_plugin_definition instanceof GroupRelationTypeInterface);
$storage = $this->entityTypeManager->getStorage('{{ configEntityType.id }}');
$this->derivatives = [];
foreach ($storage->loadMultiple() as $bundleId => $bundle) {
$args = [
'@type' => $bundle->label(),
];
$this->derivatives[$bundleId] = clone $base_plugin_definition;
$this->derivatives[$bundleId]->set('entity_bundle', $bundleId);
$this->derivatives[$bundleId]->set('label', $this->t('{{ contentEntityType.id }}:@type', $args));
$this->derivatives[$bundleId]->set('description', $this->t('Adds {{ contentEntityType.id }}:@type to groups both publicly and privately.', $args));
}
return $this->derivatives;
}
}
