function webform_preprocess_file_upload_help in Webform 8.5
Same name and namespace in other branches
- 6.x includes/webform.theme.inc \webform_preprocess_file_upload_help()
Implements hook_preprocess_file_upload_help() for file upload help text templates.
See also
\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::prepare
File
- includes/
webform.theme.inc, line 636 - Theme hooks, preprocessor, and suggestions.
Code
function webform_preprocess_file_upload_help(&$variables) {
$upload_validators = $variables['upload_validators'];
if (isset($upload_validators['webform_file_limit']) && $upload_validators['webform_file_limit'][0]) {
$variables['descriptions'][] = t('@size limit per form.', [
'@size' => format_size($upload_validators['webform_file_limit'][0]),
]);
}
// Issue #3136578: Comma-separate the list of allowed file extensions.
// @see https://www.drupal.org/project/drupal/issues/3136578
if (isset($upload_validators['webform_file_validate_extensions'])) {
foreach ($variables['descriptions'] as $index => $description) {
if ($description instanceof TranslatableMarkup && $description
->getUntranslatedString() === 'Allowed types: @extensions.') {
$arguments = $description
->getArguments();
if (is_string($arguments['@extensions']) && strpos($arguments['@extensions'], ',') === FALSE) {
$arguments['@extensions'] = preg_replace('/ +/', ', ', $arguments['@extensions']);
$variables['descriptions'][$index] = new TranslatableMarkup($description
->getUntranslatedString(), $arguments);
}
}
}
}
}