template_preprocess_file_upload_help(&$variables)
Prepares variables for file upload help text templates.
Default template: file-upload-help.html.twig.
Parameters
array $variables: An associative array containing:
- description: The normal description for this field, specified by the user.
- upload_validators: An array of upload validators as used in $element['#upload_validators'].
File
- core/modules/file/file.field.inc, line 142
- Field module functionality for the File module.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | function template_preprocess_file_upload_help(& $variables ) { $description = $variables [ 'description' ]; $upload_validators = $variables [ 'upload_validators' ]; $cardinality = $variables [ 'cardinality' ]; $descriptions = array (); if (! empty ( $description )) { $descriptions [] = FieldFilteredMarkup::create( $description ); } if (isset( $cardinality )) { if ( $cardinality == -1) { $descriptions [] = t( 'Unlimited number of files can be uploaded to this field.' ); } else { $descriptions [] = \Drupal::translation()->formatPlural( $cardinality , 'One file only.' , 'Maximum @count files.' ); } } if (isset( $upload_validators [ 'file_validate_size' ])) { $descriptions [] = t( '@size limit.' , array ( '@size' => format_size( $upload_validators [ 'file_validate_size' ][0]))); } if (isset( $upload_validators [ 'file_validate_extensions' ])) { $descriptions [] = t( 'Allowed types: @extensions.' , array ( '@extensions' => $upload_validators [ 'file_validate_extensions' ][0])); } if (isset( $upload_validators [ 'file_validate_image_resolution' ])) { $max = $upload_validators [ 'file_validate_image_resolution' ][0]; $min = $upload_validators [ 'file_validate_image_resolution' ][1]; if ( $min && $max && $min == $max ) { $descriptions [] = t( 'Images must be exactly <strong>@size</strong> pixels.' , array ( '@size' => $max )); } elseif ( $min && $max ) { $descriptions [] = t( 'Images must be larger than <strong>@min</strong> pixels. Images larger than <strong>@max</strong> pixels will be resized.' , array ( '@min' => $min , '@max' => $max )); } elseif ( $min ) { $descriptions [] = t( 'Images must be larger than <strong>@min</strong> pixels.' , array ( '@min' => $min )); } elseif ( $max ) { $descriptions [] = t( 'Images larger than <strong>@max</strong> pixels will be resized.' , array ( '@max' => $max )); } } $variables [ 'descriptions' ] = $descriptions ; } |
Please login to continue.