Automatically add description of file validators to managed_file element

Created on 22 August 2012, about 12 years ago
Updated 7 November 2023, about 1 year ago

Currently we do something like this:

  $validators = array(
    'file_validate_extensions' => array('po'),
    'file_validate_size' => array(file_upload_max_size()),
  );
  $form['file'] = array(
    '#type' => 'managed_file',
    '#title' => t('File'),
    '#size' => 50,
    '#description' => theme('file_upload_help', array('description' => t('The description of my upload field.'), 'upload_validators' => $validators)),
    '#upload_validators' => $validators,
    '#required' => TRUE,
  );

But it would be nice if the file_upload_help was added automatically and we only had to do:

  $validators = array(
    'file_validate_extensions' => array('po'),
    'file_validate_size' => array(file_upload_max_size()),
  );
  $form['file'] = array(
    '#type' => 'managed_file',
    '#title' => t('File'),
    '#description' => t('The description of my upload field.'),
    '#size' => 50,
    '#upload_validators' => $validators,
    '#required' => TRUE,
  );

Automatically adding the validation description would also easily allow other modules to alter the validators for specific elements without having to re-do the description.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
File module 

Last updated about 8 hours ago

Created by

🇺🇸United States dave reid Nebraska USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024