You are here

protected function ActivityFactory::buildActivities in Open Social 8.3

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

Build the activities based on a data array.

Parameters

array $data: An array of data to create activity from.

Return value

array An array of created activities.

1 call to ActivityFactory::buildActivities()
ActivityFactory::createActivities in modules/custom/activity_creator/src/ActivityFactory.php
Create the activities based on a data array.

File

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

Class

ActivityFactory
Class ActivityFactory to create Activity items based on ActivityLogs.

Namespace

Drupal\activity_creator

Code

protected function buildActivities(array $data) {
  $activities = [];
  $message = Message::load($data['mid']);

  // Initialize fields for new activity entity.
  $activity_fields = [
    'created' => $this
      ->getCreated($message),
    'field_activity_destinations' => $this
      ->getFieldDestinations($data),
    'field_activity_entity' => $this
      ->getFieldEntity($data),
    'field_activity_message' => $this
      ->getFieldMessage($data),
    'field_activity_output_text' => $this
      ->getFieldOutputText($message),
    'field_activity_recipient_group' => $this
      ->getFieldRecipientGroup($data),
    'field_activity_recipient_user' => $this
      ->getFieldRecipientUser($data),
    // Default activity status.
    'field_activity_status' => ACTIVITY_STATUS_RECEIVED,
    'user_id' => $this
      ->getActor($data),
  ];

  // Check if aggregation is enabled for this message type.
  // @TODO: Consider if we should put aggregation to separate service.
  if ($this
    ->getAggregationSettings($message)) {
    $activities = $this
      ->buildAggregatedActivites($data, $activity_fields);
  }
  else {
    $activity = Activity::create($activity_fields);
    $activity
      ->save();
    $activities[] = $activity;
  }
  return $activities;
}