function webform_preprocess_file_link in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.theme.inc \webform_preprocess_file_link()
Implements hook_preprocess_file_link() for file link templates.
See also
webform_file_access
File
- includes/
webform.theme.inc, line 677 - Theme hooks, preprocessor, and suggestions.
Code
function webform_preprocess_file_link(&$variables) {
/** @var \Drupal\file\FileInterface $file */
$file = $variables['file'];
$file = $file instanceof File ? $file : File::load($file->fid);
// Remove link to temporary anonymous private file uploads.
if ($file
->isTemporary() && $file
->getOwner() && $file
->getOwner()
->isAnonymous() && strpos($file
->getFileUri(), 'private://webform/') === 0) {
$variables['link'] = $file
->getFilename();
}
// Add file size variable to Claro theme.
if (empty($variables['file_size']) && \Drupal::service('webform.theme_manager')
->isActiveTheme('claro')) {
$variables['file_size'] = format_size($file
->getSize(), \Drupal::languageManager()
->getCurrentLanguage()
->getId());
}
}