You are here

function social_follow_content_event_enrollment_follow in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  2. 8 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  3. 8.2 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  4. 8.3 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  5. 8.4 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  6. 8.6 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  7. 8.7 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  8. 8.8 modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  9. 10.3.x modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  10. 10.0.x modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  11. 10.1.x modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()
  12. 10.2.x modules/social_features/social_follow_content/social_follow_content.module \social_follow_content_event_enrollment_follow()

Automatically follow content when user enrolls the event.

2 calls to social_follow_content_event_enrollment_follow()
social_follow_content_event_enrollment_insert in modules/social_features/social_follow_content/social_follow_content.module
Implements hook_ENTITY_TYPE_insert().
social_follow_content_event_enrollment_update in modules/social_features/social_follow_content/social_follow_content.module
Implements hook_ENTITY_TYPE_update().

File

modules/social_features/social_follow_content/social_follow_content.module, line 34
The Social Follow Content module.

Code

function social_follow_content_event_enrollment_follow(EntityInterface $entity) {
  if ($entity->field_enrollment_status->value) {

    // Check if user already follow this content.
    // Only logged in users can follow content.
    $account = \Drupal::currentUser();
    if (!$account
      ->isAuthenticated()) {
      return;
    }
    $properties = [
      'uid' => $account
        ->id(),
      'entity_type' => 'node',
      'entity_id' => $entity->field_event->target_id,
      'flag_id' => 'follow_content',
    ];
    $flaggings = \Drupal::entityTypeManager()
      ->getStorage('flagging')
      ->loadByProperties($properties);
    $flagging = reset($flaggings);
    if (empty($flagging)) {
      $flagging = Flagging::create($properties);
      if ($flagging) {
        $flagging
          ->save();
        $message = t('You have successfully enrolled to this event. Also you are now following the event, which means you will receive notifications when a new comment is placed.');
        drupal_set_message($message);
      }
    }
  }
}