You are here

class SocialGroupHelperService in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  2. 8 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  3. 8.3 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  4. 8.4 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  5. 8.5 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  6. 8.6 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  7. 8.7 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  8. 8.8 modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  9. 10.3.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  10. 10.0.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  11. 10.1.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService
  12. 10.2.x modules/social_features/social_group/src/SocialGroupHelperService.php \Drupal\social_group\SocialGroupHelperService

Class SocialGroupHelperService.

@package Drupal\social_group

Hierarchy

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_group
View 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

Namesort descending Modifiers Type Description Overrides
SocialGroupHelperService::getGroupFromEntity public static function Returns a group id from a entity (post, node).
SocialGroupHelperService::__construct public function Constructor.