class SocialGroupHelperService in Open Social 8.2
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8.3 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8.4 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8.5 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8.6 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8.7 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 8.8 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 10.3.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 10.0.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 10.1.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
- 10.2.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
Class SocialGroupHelperService.
@package Drupal\social_group
Hierarchy
- class \Drupal\social_group\SocialGroupHelperService
Expanded class hierarchy of SocialGroupHelperService
3 files declare their use of SocialGroupHelperService
- GroupActivityContext.php in modules/
custom/ activity_basics/ src/ Plugin/ ActivityContext/ GroupActivityContext.php - PostViewBuilder.php in modules/
social_features/ social_post/ src/ PostViewBuilder.php - social_group.module in modules/
social_features/ social_group/ social_group.module - The Social group module.
1 string reference to 'SocialGroupHelperService'
- social_group.services.yml in modules/
social_features/ social_group/ social_group.services.yml - modules/social_features/social_group/social_group.services.yml
1 service uses SocialGroupHelperService
- social_group.helper_service in modules/
social_features/ social_group/ social_group.services.yml - Drupal\social_group\SocialGroupHelperService
File
- modules/
social_features/ social_group/ src/ SocialGroupHelperService.php, line 14
Namespace
Drupal\social_groupView source
class SocialGroupHelperService {
/**
* Constructor.
*/
public function __construct() {
}
/**
* Returns a group id from a entity (post, node).
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialGroupHelperService:: |
public static | function | Returns a group id from a entity (post, node). | |
SocialGroupHelperService:: |
public | function | Constructor. |