public static function SocialGroupHelperService::getGroupFromEntity in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.2 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.3 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.4 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.5 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.6 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.7 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 8.8 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 10.3.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 10.0.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 10.1.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
- 10.2.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService::getGroupFromEntity()
Returns a group id from a entity (post, node).
2 calls to SocialGroupHelperService::getGroupFromEntity()
- GroupActivityContext::getRecipients in modules/
custom/ activity_basics/ src/ Plugin/ ActivityContext/ GroupActivityContext.php - Returns a batched list of recipients for this context.
- _social_group_get_current_group in modules/
social_features/ social_group/ social_group.module - Get current Group entity from the route.
File
- modules/
social_features/ social_group/ src/ SocialGroupHelperService.php, line 26
Class
- SocialGroupHelperService
- Class SocialGroupHelperService.
Namespace
Drupal\social_groupCode
public static function getGroupFromEntity($entity) {
$gid = NULL;
// Special cases for comments.
// Returns the entity to which the comment is attached.
if ($entity['target_type'] === 'comment') {
$comment = \Drupal::entityTypeManager()
->getStorage('comment')
->load($entity['target_id']);
$commented_entity = $comment
->getCommentedEntity();
$entity['target_type'] = $commented_entity
->getEntityTypeId();
$entity['target_id'] = $commented_entity
->id();
}
if ($entity['target_type'] === 'post') {
/* @var /Drupal/social_post/Entity/Post $post */
$post = Post::load($entity['target_id']);
$recipient_group = $post
->get('field_recipient_group')
->getValue();
if (!empty($recipient_group)) {
$gid = $recipient_group['0']['target_id'];
}
}
elseif ($entity['target_type'] === 'node') {
// Try to load the entity.
if ($node = Node::load($entity['target_id'])) {
// Try to load group content from entity.
if ($groupcontent = GroupContent::loadByEntity($node)) {
// Potentially there are more than one.
$groupcontent = reset($groupcontent);
// Set the group id.
$gid = $groupcontent
->getGroup()
->id();
}
}
}
return $gid;
}