You are here

public function ActivityFactory::getActivityRelatedEntity in Open Social 10.3.x

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.2 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  4. 8.3 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  5. 8.4 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  6. 8.5 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  7. 8.6 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  8. 8.7 modules/custom/activity_creator/src/ActivityFactory.php \Drupal\activity_creator\ActivityFactory::getActivityRelatedEntity()
  9. 8.8 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.

1 call to ActivityFactory::getActivityRelatedEntity()
ActivityFactory::getAggregationAuthorsCount in modules/custom/activity_creator/src/ActivityFactory.php
Get unique authors number for activity aggregation.

File

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

Class

ActivityFactory
Class ActivityFactory to create Activity items based on ActivityLogs.

Namespace

Drupal\activity_creator

Code

public 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 = $this->entityTypeManager
      ->getStorage('comment');

    // @todo Check if comment published?
    $comment = $comment_storage
      ->load($related_object['target_id']);
    if ($comment) {
      $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 = $this->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(),
        ];
      }
    }
  }
  elseif (isset($related_object['target_type']) && $related_object['target_type'] === 'event_enrollment') {
    $entity_storage = $this->entityTypeManager
      ->getStorage($related_object['target_type']);
    $entity = $entity_storage
      ->load($related_object['target_id']);
    if ($entity instanceof EventEnrollmentInterface) {

      /** @var \Drupal\social_event\Entity\EventEnrollment $entity */
      $event_id = $entity
        ->getFieldValue('field_event', 'target_id');
      if (!empty($event_id)) {
        $related_object = [
          'target_type' => 'node',
          'target_id' => $event_id,
        ];
      }
    }
  }
  $this->moduleHandler
    ->alter('activity_creator_related_entity_object', $related_object, $data);
  return $related_object;
}