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

Issue #3294952 by kristiaanvandeneynde: Introduce GroupContent::getEntityId()

parent 29eb1b50
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -33,7 +33,7 @@ interface GroupContentInterface extends ContentEntityInterface, EntityOwnerInter
/**
* Returns the group ID the relationship belongs to.
*
* @return string
* @return int
* 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.
*
......
......@@ -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());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment