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(),
        ];
      }
    }
    // We return commented entity as related object for all other comments.
    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(),
          ];
        }
      }
    }
    // We return Event as related object for all Event Enrollments.
    elseif (isset($related_object['target_type']) && $related_object['target_type'] === 'event_enrollment') {
      $entity_storage = \Drupal::entityTypeManager()
        ->getStorage($related_object['target_type']);
      $entity = $entity_storage->load($related_object['target_id']);

      /** @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,
        ];
      }
    }
    return $related_object;
  }
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(),
        ];
      }
    }
    // We return commented entity as related object for all other comments.
    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(),
          ];
        }
      }
    }
    // We return Event as related object for all Event Enrollments.
    elseif (isset($related_object['target_type']) && $related_object['target_type'] === 'event_enrollment') {
      $entity_storage = \Drupal::entityTypeManager()
        ->getStorage($related_object['target_type']);
      $entity = $entity_storage->load($related_object['target_id']);

      /** @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,
        ];
      }
    }
    return $related_object;
  }
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 ( ) , ] ; } } // We return commented entity as related object for all other comments. 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 ( ) , ] ; } } } // We return Event as related object for all Event Enrollments. elseif ( isset ( $ related_object [ 'target_type' ] ) && $ related_object [ 'target_type' ] === 'event_enrollment' ) { $ entity_storage = \ Drupal :: entityTypeManager ( ) -> getStorage ( $ related_object [ 'target_type' ] ) ; $ entity = $ entity_storage -> load ( $ related_object [ 'target_id' ] ) ; /** @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 , ] ; } } return $ related_object ; }
Get related entity for activity aggregation.
Get related entity for activity aggregation .