- Issue created by @hungdo
- Status changed to Needs review
over 1 year ago 3:11am 14 July 2023 - last update
over 1 year ago 7 pass - last update
11 months ago 7 pass - last update
11 months ago 7 pass
Update wrong group content that does reference to the term.
In the loadReferencingEntitiesOfType function, we are getting all entities by using following code
$entities = $this->entityTypeManager->getStorage($entityType)
->loadByProperties([$fieldName => $term->id()]);
In a case, $entityType is group_content and $fieldName is entity_id, this will return all entities as long as they have entity_id equal $term->id(), this is wrong because the group content plugin can be group_node or group_media or group_term. However the termId can be the same as the node id or media id. So in this case, we need to query all entities that have group_term type only.
Suggestion change.
$entities = $this->entityTypeManager->getStorage($entityType)
->loadByProperties([$fieldName => $term->id()]);
if ($entityType == 'group_content') {
foreach($entities as $entity) {
/** @var \Drupal\group\Entity\GroupContentInterface $entity */
if (strpos($entity->getContentPlugin()->getPluginId(), 'group_term') !== FALSE) {
$referencingEntities = array_merge($referencingEntities, [$entity]);
}
}
}
else {
$referencingEntities = array_merge($referencingEntities, $entities);
}
Needs review
2.0
Code