Problem/Motivation

The upload field shows a description 'Unlimited number of files can be uploaded to this field.'.
In my php.ini there is a restriction for 'max_file_uploads' – so it is not unlimited, but the value of max_file_uploads. The default value is max 20 files.

Proposed resolution

Change the help text like this:

function media_library_bulk_upload_preprocess_file_upload_help(&$variables) {
  $php_max_file_uploads = ini_get('max_file_uploads');
  $cardinality = $variables['cardinality'];
  if (isset($cardinality) && isset($php_max_file_uploads)) {
    if ($cardinality == -1 && $php_max_file_uploads > 0) {
      $cardinality = $php_max_file_uploads;
      $variables['cardinality'] = $cardinality;
      $description = \Drupal::translation()->formatPlural($cardinality, 'One file only.', 'Maximum @count files.');
      $key = array_search(t('Unlimited number of files can be uploaded to this field.'),$variables['descriptions']);
      $variables['descriptions'][$key] = $description;
    }
  }
}

Remaining tasks

This issues should be solved in core: #3196550: File fields with cardinality unlimited does not respect PHP's max_file_uploads setting

Comments

tfranz created an issue. See original summary.

tfranz’s picture

Attached is my patch unless the core issue is solved.

anybody’s picture

Issue summary: View changes