You are here

function uc_file_user_view in Ubercart 8.4

Same name and namespace in other branches
  1. 6.2 uc_file/uc_file.module \uc_file_user_view()
  2. 7.3 uc_file/uc_file.module \uc_file_user_view()

Implements hook_ENTITY_TYPE_view() for user entities.

File

uc_file/uc_file.module, line 73
Allows products to be associated with downloadable files.

Code

function uc_file_user_view(array &$build, AccountInterface $account, EntityViewDisplayInterface $display, $view_mode) {
  $user = \Drupal::currentUser();
  $connection = \Drupal::database();

  // If user has files and permission to view them, put a link
  // on the user's profile.
  $existing_download = $connection
    ->query('SELECT fid FROM {uc_file_users} WHERE uid = :uid', [
    ':uid' => $account
      ->id(),
  ])
    ->fetchField();
  $existing_download = TRUE;
  if ($view_mode == 'full' && $existing_download && ($user
    ->id() == $account
    ->id() || $user
    ->hasPermission('view all downloads'))) {
    $build['uc_file_download'] = [
      '#type' => 'item',
      '#title' => t('File downloads'),
      '#markup' => Link::createFromRoute(t('Click here to view your file downloads.'), 'uc_file.user_downloads', [
        'user' => $account
          ->id(),
      ])
        ->toString(),
    ];
  }
}