You are here

function social_event_managers_activity_recipient_organizer_alter in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  2. 8.4 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  3. 8.5 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  4. 8.6 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  5. 8.8 modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  6. 10.3.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  7. 10.0.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  8. 10.1.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()
  9. 10.2.x modules/social_features/social_event/modules/social_event_managers/social_event_managers.module \social_event_managers_activity_recipient_organizer_alter()

Implements hook_activity_recipient_organizer_alter().

File

modules/social_features/social_event/modules/social_event_managers/social_event_managers.module, line 367
Contains social_event_managers.module.

Code

function social_event_managers_activity_recipient_organizer_alter(array &$recipients, Node $event, $data) {
  $receiver = '';
  $organizers = $event
    ->get('field_event_managers')
    ->getValue();
  if ($data['target_type'] === 'event_enrollment' && !empty($data['target_id'])) {
    $enrollment = EventEnrollment::load($data['target_id']);
    $receiver = $enrollment
      ->getAccount();
  }

  // If there are more organizers we want them to receive a notification too
  // so we add them to the array of recipients.
  if (!empty($organizers)) {
    foreach ($organizers as $organizer) {

      // We don't want Organizers to receive activity_on_events_im_organizing.
      // It will already receive it as part of a different context.
      if (!empty($receiver) && $organizer['target_id'] === $receiver) {
        continue;
      }

      // Make sure we don't add the people twice.
      if (!in_array($organizer['target_id'], array_column($recipients, 'target_id'))) {
        $recipients[] = [
          'target_type' => 'user',
          'target_id' => $organizer['target_id'],
        ];
      }
    }
  }
}