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.

Comments

Dave Reid’s picture

Issue tags: +sprint, +Media Initiative
Dave Reid’s picture

Issue summary: View changes
Issue tags: -sprint +D8Media
Dave Reid’s picture

Assigned: Dave Reid » Unassigned
Category: Feature request » Bug report

I consider this a bug that when I add extra validators to a managed file element, the user is not informed at all about what the new requirements are.

AndyF’s picture

Assigned: Unassigned » AndyF

I'm gonna take a stab at this as part of familiarizing myself with D8.

AndyF’s picture

Status: Active » Needs review
FileSize
22.22 KB

Here's a first attempt. There were a couple of things I thought might be nice for the developer, but I left them out to keep the patch focused:

  • Allow the dev to specify some custom validation text, such as A Gettext Portable Object file.
  • Give custom validators a mechanism to influence the description.

Feedback appreciated, thanks

AndyF’s picture

And some minor clean-up.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.