You are here

function activity_creator_entity_view in Open Social 8.2

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

Implements hook_entity_view().

Mark notifications as read.

TODO: Maybe this should be an event subscriber service

File

modules/custom/activity_creator/activity_creator.module, line 206
Activity Creator module file.

Code

function activity_creator_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($view_mode === 'full') {
    $account = \Drupal::currentUser();

    // @TODO Check if this entity is even specified in ActivityLoggerFactory
    \Drupal::service('activity_creator.activity_notifications')
      ->markEntityNotificationsAsRead($account, $entity);
  }

  // Generate the output text for the user in his selected language.
  if ($entity instanceof Activity && !empty($entity
    ->get('field_activity_message')->target_id)) {
    $message = Message::load($entity
      ->get('field_activity_message')->target_id);
    if ($message instanceof Message) {

      // Get the text in the users language.
      $output = \Drupal::service('activity_creator.activity_factory')
        ->getMessageText($message);

      // Replace the old text with the correct one.
      $build['field_activity_output_text'][0]['#text'] = $output[0];
    }
  }
}