function activity_creator_entity_view in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.2 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.3 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.4 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.5 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.6 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.7 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 8.8 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 10.3.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 10.0.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 10.1.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_view()
- 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 205 - 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];
}
}
}