You are here

public static function ActivityFactory::getActivityRelatedEntity in Open Social 8.2

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  2. 8 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  3. 8.3 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  4. 8.4 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  5. 8.5 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  6. 8.6 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  7. 8.7 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  8. 8.8 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  9. 10.3.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  10. 10.0.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  11. 10.1.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  12. 10.2.x modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()

Get related entity for activity aggregation.

5 calls to ActivityFactory::getActivityRelatedEntity()
ActivityFactory::getAggregationAuthorsCount in modules/custom/activity_creator/src/ActivityFactory.php
Get unique authors number for activity aggregation.
ContentInMyGroupActivityContext::getRecipients in modules/custom/activity_basics/src/Plugin/ActivityContext/ContentInMyGroupActivityContext.php
Returns a batched list of recipients for this context.
FollowContentActivityContext::getRecipients in modules/social_features/social_follow_content/src/Plugin/ActivityContext/FollowContentActivityContext.php
Returns a batched list of recipients for this context.
OwnerActivityContext::getRecipients in modules/custom/activity_basics/src/Plugin/ActivityContext/OwnerActivityContext.php
Returns a batched list of recipients for this context.
ProfileActivityContext::getRecipients in modules/custom/activity_basics/src/Plugin/ActivityContext/ProfileActivityContext.php
Returns a batched list of recipients for this context.

File

modules/custom/activity_creator/src/ActivityFactory.php, line 276

Class

ActivityFactory
Class ActivityFactory to create Activity items based on ActivityLogs.

Namespace

Drupal\activity_creator

Code

public static function getActivityRelatedEntity($data) {
  $related_object = $data['related_object'][0];

  // We return parent comment as related object as comment
  // for create_comment_reply messages.
  if ($data['message_template'] === 'create_comment_reply') {
    $comment_storage = \Drupal::entityTypeManager()
      ->getStorage('comment');

    // @TODO: Check if comment published?
    $comment = $comment_storage
      ->load($related_object['target_id']);
    $parent_comment = $comment
      ->getParentComment();
    if (!empty($parent_comment)) {
      $related_object = [
        'target_type' => $parent_comment
          ->getEntityTypeId(),
        'target_id' => $parent_comment
          ->id(),
      ];
    }
  }
  elseif (isset($related_object['target_type']) && $related_object['target_type'] === 'comment') {
    $comment_storage = \Drupal::entityTypeManager()
      ->getStorage('comment');

    // @todo: Check if comment published?
    $comment = $comment_storage
      ->load($related_object['target_id']);
    if ($comment) {
      $commented_entity = $comment
        ->getCommentedEntity();
      if (!empty($commented_entity)) {
        $related_object = [
          'target_type' => $commented_entity
            ->getEntityTypeId(),
          'target_id' => $commented_entity
            ->id(),
        ];
      }
    }
  }
  return $related_object;
}