Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group-3397063
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
group-3397063
Commits
c752f18e
Commit
c752f18e
authored
2 years ago
by
Kristiaan Van den Eynde
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3294952
by kristiaanvandeneynde: Introduce GroupContent::getEntityId()
parent
29eb1b50
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Entity/GroupContent.php
+11
-6
11 additions, 6 deletions
src/Entity/GroupContent.php
src/Entity/GroupContentInterface.php
+9
-1
9 additions, 1 deletion
src/Entity/GroupContentInterface.php
tests/src/Kernel/GroupContentTest.php
+5
-0
5 additions, 0 deletions
tests/src/Kernel/GroupContentTest.php
with
25 additions
and
7 deletions
src/Entity/GroupContent.php
+
11
−
6
View file @
c752f18e
...
...
@@ -126,6 +126,16 @@ class GroupContent extends ContentEntityBase implements GroupContentInterface {
return
$this
->
get
(
'entity_id'
)
->
entity
;
}
/**
* {@inheritdoc}
*/
public
function
getEntityId
()
{
if
(
$this
->
getPlugin
()
->
getRelationType
()
->
handlesConfigEntityType
())
{
return
$this
->
get
(
'entity_id'
)
->
entity
->
getConfigEntityId
();
}
return
$this
->
get
(
'entity_id'
)
->
target_id
;
}
/**
* {@inheritdoc}
*/
...
...
@@ -290,12 +300,7 @@ class GroupContent extends ContentEntityBase implements GroupContentInterface {
$group_id
=
$this
->
get
(
'gid'
)
->
target_id
;
$plugin_id
=
$this
->
getRelationshipType
()
->
getPluginId
();
if
(
$this
->
getPlugin
()
->
getRelationType
()
->
handlesConfigEntityType
())
{
$entity_id
=
$this
->
get
(
'entity_id'
)
->
entity
->
getConfigEntityId
();
}
else
{
$entity_id
=
$this
->
get
(
'entity_id'
)
->
target_id
;
}
$entity_id
=
$this
->
getEntityId
();
// A specific group gets any content, regardless of plugin used.
// E.g.: A group's list of entities can be flushed with this.
...
...
This diff is collapsed.
Click to expand it.
src/Entity/GroupContentInterface.php
+
9
−
1
View file @
c752f18e
...
...
@@ -33,7 +33,7 @@ interface GroupContentInterface extends ContentEntityInterface, EntityOwnerInter
/**
* Returns the group ID the relationship belongs to.
*
* @return
str
in
g
* @return in
t
* The group ID the relationship belongs to.
*/
public
function
getGroupId
();
...
...
@@ -62,6 +62,14 @@ interface GroupContentInterface extends ContentEntityInterface, EntityOwnerInter
*/
public
function
getEntity
();
/**
* Returns the ID of the related entity.
*
* @return int|string
* The ID of the related entity.
*/
public
function
getEntityId
();
/**
* Returns the group relation that handles the relationship.
*
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/GroupContentTest.php
+
5
−
0
View file @
c752f18e
...
...
@@ -91,6 +91,9 @@ class GroupContentTest extends GroupKernelTestBase {
/**
* Tests the retrieval of the grouped entity.
*
* @covers ::getEntity
* @covers ::getEntityId
*/
public
function
testGetEntity
()
{
// Create a group type and enable adding users and node types as content.
...
...
@@ -105,12 +108,14 @@ class GroupContentTest extends GroupKernelTestBase {
$account
=
$this
->
createUser
();
$group_content
=
$group
->
addRelationship
(
$account
,
'user_as_content'
);
$this
->
assertEquals
(
$account
->
id
(),
$group_content
->
getEntity
()
->
id
());
$this
->
assertEquals
(
$account
->
id
(),
$group_content
->
getEntityId
());
$this
->
assertEquals
(
'user'
,
$group_content
->
getEntity
()
->
getEntityTypeId
());
$node_type
=
$this
->
createNodeType
();
$group_content
=
$group
->
addRelationship
(
$node_type
,
'node_type_as_content'
);
$this
->
assertEquals
(
'node_type'
,
$group_content
->
getEntity
()
->
getEntityTypeId
());
$this
->
assertEquals
(
$node_type
->
id
(),
$group_content
->
getEntity
()
->
id
());
$this
->
assertEquals
(
$node_type
->
id
(),
$group_content
->
getEntityId
());
}
/**
...
...
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