You are here

function private_message_user_view in Private Message 8.2

Same name and namespace in other branches
  1. 8 private_message.module \private_message_user_view()

Implements hook_ENTITY_TYPE_view().

Adds new elements to the User entity.

See also

hook_entity_view()

File

./private_message.module, line 180
Contains hooks for the private message module.

Code

function private_message_user_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($display
    ->getComponent('linked_username')) {
    if (\Drupal::currentUser()
      ->hasPermission('access user profiles')) {
      $url = Url::fromRoute('entity.user.canonical', [
        'user' => $entity
          ->id(),
      ]);
      $build['linked_username'] = [
        '#prefix' => '<p class="username">',
        '#suffix' => '</p>',
        '#type' => 'link',
        '#url' => $url,
        '#title' => $entity
          ->getDisplayName(),
      ];
    }
    else {
      $build['linked_username'] = [
        '#prefix' => '<p class="username">',
        '#suffix' => '</p>',
        '#markup' => $entity
          ->getDisplayName(),
      ];
    }
  }
  \Drupal::service('private_message.service')
    ->createRenderablePrivateMessageThreadLink($build, $entity, $display, $view_mode);
}