Skip to content
Snippets Groups Projects
Commit 9cbf813d authored by Kristiaan Van den Eynde's avatar Kristiaan Van den Eynde
Browse files

Change variable names and add tests.

parent de1f4cfa
No related branches found
No related tags found
1 merge request!196Set shared: false on relation type handler decorators.
......@@ -31,7 +31,7 @@ class GroupServiceProvider extends ServiceProviderBase {
[]
);
$handlers = [
$handler_info = [
'access_control' => 'Drupal\group\Plugin\Group\RelationHandler\EmptyAccessControl',
'entity_reference' => 'Drupal\group\Plugin\Group\RelationHandler\EmptyEntityReference',
'operation_provider' => 'Drupal\group\Plugin\Group\RelationHandler\EmptyOperationProvider',
......@@ -41,10 +41,10 @@ class GroupServiceProvider extends ServiceProviderBase {
];
// Keep track of which services are expected to be decorated.
$decoratable_service_ids = array_map(fn($handler) => "group.relation_handler.$handler", array_keys($handlers));
$decoratable_service_ids = array_map(fn($handler_id) => "group.relation_handler.$handler_id", array_keys($handler_info));
// Keep track of the services that represent each relation type's handlers.
$services = [];
$handlers = [];
foreach ($discovery->getDefinitions() as $group_relation_type_id => $group_relation_type) {
assert($group_relation_type instanceof GroupRelationTypeInterface);
// Skip plugins that whose provider is not installed.
......@@ -52,28 +52,28 @@ class GroupServiceProvider extends ServiceProviderBase {
continue;
}
foreach ($handlers as $handler => $handler_class) {
$service_name = "group.relation_handler.$handler.$group_relation_type_id";
foreach ($handler_info as $handler_id => $handler_class) {
$service_name = "group.relation_handler.$handler_id.$group_relation_type_id";
$decoratable_service_ids[] = $service_name;
// Either get the existing service or define it and pass it the default
// one to decorate.
$definition = $container->has($service_name)
? $container->getDefinition($service_name)
: new Definition($handler_class, [new Reference("group.relation_handler.$handler")]);
: new Definition($handler_class, [new Reference("group.relation_handler.$handler_id")]);
// All handlers must be public and cannot be shared.
$definition->setPublic(TRUE);
$definition->setShared(FALSE);
$container->setDefinition($service_name, $definition);
$services[$service_name] = new Reference($service_name);
$handlers[$service_name] = new Reference($service_name);
}
}
// Add the services to the relation type manager using a service locator.
// Add the handlers to the relation type manager using a service locator.
$manager = $container->getDefinition('group_relation_type.manager');
$manager->addArgument(ServiceLocatorTagPass::register($container, $services));
$manager->addArgument(ServiceLocatorTagPass::register($container, $handlers));
// Set the shared flag to FALSE for any service that decorates a base
// handler or a relation type specific handler. This is a quality-of-life
......
......@@ -55,4 +55,12 @@ class RelationHandlerTest extends GroupKernelTestBase {
$this->assertSame($expected, $relation_manager->getPermissionProvider('entity_test_relation')->getAdminPermission(), $message);
}
/**
* Tests that decorators are automatically set as non-shared services.
*/
public function testDecoratorNotShared() {
$this->assertFalse($this->container->getDefinition('group.relation_handler_decorator.permission_provider.bar')->isShared());
$this->assertFalse($this->container->getDefinition('group.relation_handler_decorator.permission_provider.baz.node_relation')->isShared());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment