In some case there are more than one description for the same variable due to https://git.drupalcode.org/project/drupal/-/commit/5067812f078395a1bcbbe... ( https://www.drupal.org/node/3363700 β )
Example :
100 MB limit.
10 MB limit.
Allowed types: gif, jpg, jpeg, png, bmp, eps, tif, pict, psd, txt, rtf, html, odf, pdf, doc, docx, ppt, pptx, xls, xlsx, xml, avi, mov, mp3, mp4, ogg, wav, bz2, dmg, gz, jar, rar, sit, svg, tar, zip.
Allowed types: png, gif, jpg, jpeg.
Create an Webform Element with a managed_file like this
'#type' => 'managed_file',
'#title' => t('File'),
'#upload_location' => 'public://' . $element['#webform'],
'#upload_validators' => [
'FileExtension' => ['extensions' => 'png gif jpg jpeg'],
'FileSizeLimit' => ['fileLimit' => 10485760],
],
];
Inside template_preprocess_file_upload_help, set description type in array to prevent different validators for the same variable
for example replace
if (isset($upload_validators['file_validate_size'])) {
@trigger_error('\'file_validate_size\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileSizeLimit\' constraint instead. See https://www.drupal.org/node/3363700', E_USER_DEPRECATED);
$descriptions[] = t('@size limit.', ['@size' => ByteSizeMarkup::create($upload_validators['file_validate_size'][0])]);
}
if (isset($upload_validators['FileSizeLimit'])) {
$descriptions[] = t('@size limit.', ['@size' => ByteSizeMarkup::create($upload_validators['FileSizeLimit']['fileLimit'])]);
}
if (isset($upload_validators['file_validate_extensions'])) {
@trigger_error('\'file_validate_extensions\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileExtension\' constraint instead. See https://www.drupal.org/node/3363700', E_USER_DEPRECATED);
$descriptions[] = t('Allowed types: @extensions.', ['@extensions' => $upload_validators['file_validate_extensions'][0]]);
}
if (isset($upload_validators['FileExtension'])) {
$descriptions[] = t('Allowed types: @extensions.', ['@extensions' => $upload_validators['FileExtension']['extensions']]);
}
by
if (isset($upload_validators['file_validate_size'])) {
@trigger_error('\'file_validate_size\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileSizeLimit\' constraint instead. See https://www.drupal.org/node/3363700', E_USER_DEPRECATED);
$descriptions['size'] = t('@size limit.', ['@size' => ByteSizeMarkup::create($upload_validators['file_validate_size'][0])]);
}
if (isset($upload_validators['FileSizeLimit'])) {
$descriptions['size'] = t('@size limit.', ['@size' => ByteSizeMarkup::create($upload_validators['FileSizeLimit']['fileLimit'])]);
}
if (isset($upload_validators['file_validate_extensions'])) {
@trigger_error('\'file_validate_extensions\' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use the \'FileExtension\' constraint instead. See https://www.drupal.org/node/3363700', E_USER_DEPRECATED);
$descriptions['extensions'] = t('Allowed types: @extensions.', ['@extensions' => $upload_validators['file_validate_extensions'][0]]);
}
if (isset($upload_validators['FileExtension'])) {
$descriptions['extensions'] = t('Allowed types: @extensions.', ['@extensions' => $upload_validators['FileExtension']['extensions']]);
}
Closed: duplicate
10.2 β¨