Update group content not correctly

Created on 14 July 2023, over 1 year ago
Updated 5 January 2024, 12 months ago

Problem/Motivation

Update wrong group content that does reference to the term.

Proposed resolution

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);
}
πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States hungdo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024