function opigno_messaging_private_message_thread_view_alter in Opigno messaging 8
Same name and namespace in other branches
- 3.x opigno_messaging.module \opigno_messaging_private_message_thread_view_alter()
Implements hook_ENTITY_TYPE_view_alter().
Changes 'last_message' view mode to 'thread_preview' if 'private_message_thread' view mode is 'preview'.
See also
private_message_private_message_thread_view()
File
- ./
opigno_messaging.module, line 587 - Contains opigno_messaging.module.
Code
function opigno_messaging_private_message_thread_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if (isset($build['last_message']) && $build['#view_mode'] === 'preview') {
/** @var \Drupal\private_message\Entity\PrivateMessageThreadInterface $entity */
$messages = $entity
->getMessages();
$last_message = array_pop($messages);
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder('private_message');
$build['last_message'] = $view_builder
->view($last_message, 'thread_preview');
}
}