function hook_uc_download_authorize in Ubercart 8.4
Same name and namespace in other branches
- 7.3 uc_file/uc_file.api.php \hook_uc_download_authorize()
Gives clearance to a user to download a file.
By default the uc_file module can implement 3 restrictions on downloads: by number of IP addresses downloaded from, by number of downloads, and by a set expiration date. Developers wishing to add further restrictions can do so by implementing this hook. After the 3 aforementioned restrictions are checked, the uc_file module will check for implementations of this hook.
Parameters
\Drupal\Core\Session\AccountInterface $user: The Drupal user object that has requested the download.
$file_download: The file download object as defined as a row from the uc_file_users table that grants the user the download
Return value
bool TRUE or FALSE depending on whether the user is to be permitted download of the requested files. When a implementation returns FALSE it should set an error message in Drupal using \Drupal::messenger() to inform customers of what is going on.
1 invocation of hook_uc_download_authorize()
- DownloadController::validateDownload in uc_file/
src/ Controller/ DownloadController.php - Performs first-pass authorization. Calls authorization hooks afterwards.
File
- uc_file/
uc_file.api.php, line 36 - Hooks provided by the File Downloads module.
Code
function hook_uc_download_authorize(AccountInterface $user, $file_download) {
if (!$user->status) {
\Drupal::messenger()
->addError(t("This account has been banned and can't download files anymore."));
return FALSE;
}
else {
return TRUE;
}
}