Automatically add description of file validators to managed_file element

Created on 22 August 2012, almost 13 years ago
Updated 9 March 2023, about 2 years 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 review

Version

10.1 โœจ

Component
File moduleย  โ†’

Last updated about 20 hours ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States dave reid Nebraska USA

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

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