Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
group
Commits
9cbf813d
Commit
9cbf813d
authored
6 months ago
by
Kristiaan Van den Eynde
Browse files
Options
Downloads
Patches
Plain Diff
Change variable names and add tests.
parent
de1f4cfa
No related branches found
No related tags found
1 merge request
!196
Set shared: false on relation type handler decorators.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/GroupServiceProvider.php
+9
-9
9 additions, 9 deletions
src/GroupServiceProvider.php
tests/src/Kernel/RelationHandlerTest.php
+8
-0
8 additions, 0 deletions
tests/src/Kernel/RelationHandlerTest.php
with
17 additions
and
9 deletions
src/GroupServiceProvider.php
+
9
−
9
View file @
9cbf813d
...
...
@@ -31,7 +31,7 @@ class GroupServiceProvider extends ServiceProviderBase {
[]
);
$handler
s
=
[
$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
(
$handler
s
));
$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.
$
service
s
=
[];
$
handler
s
=
[];
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
(
$handler
s
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
);
$
service
s
[
$service_name
]
=
new
Reference
(
$service_name
);
$
handler
s
[
$service_name
]
=
new
Reference
(
$service_name
);
}
}
// Add the
service
s to the relation type manager using a service locator.
// Add the
handler
s to the relation type manager using a service locator.
$manager
=
$container
->
getDefinition
(
'group_relation_type.manager'
);
$manager
->
addArgument
(
ServiceLocatorTagPass
::
register
(
$container
,
$
service
s
));
$manager
->
addArgument
(
ServiceLocatorTagPass
::
register
(
$container
,
$
handler
s
));
// 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
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/RelationHandlerTest.php
+
8
−
0
View file @
9cbf813d
...
...
@@ -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
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment