Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
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.
Comment | File | Size | Author |
---|---|---|---|
#37 | diff_33-37.txt | 7.82 KB | vsujeetkumar |
#37 | 1744226-37.patch | 28.01 KB | vsujeetkumar |
#33 | interdiff_32-33.txt | 11.45 KB | Tanuj. |
#33 | 1744226-33.patch | 28.34 KB | Tanuj. |
#32 | reroll_diff_18-32.txt | 30.52 KB | Tanuj. |
Comments
Comment #1
Dave ReidComment #2
Dave ReidComment #3
Dave ReidI 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.
Comment #4
AndyF CreditAttribution: AndyF commentedI'm gonna take a stab at this as part of familiarizing myself with D8.
Comment #5
AndyF CreditAttribution: AndyF commentedHere'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:
Feedback appreciated, thanks
Comment #6
AndyF CreditAttribution: AndyF commentedAnd some minor clean-up.
Comment #13
MacSim CreditAttribution: MacSim commentedOn a Drupal 8.7, the installation of the patch #6 fails :
But even with that fail, I see the description under my custom field
Comment #14
MacSim CreditAttribution: MacSim commentedComment #15
MacSim CreditAttribution: MacSim commentedRewrited the patch in #6 to be compatible with a Drupal 8.7.4
I hope I didn't forget anything
Comment #16
MacSim CreditAttribution: MacSim commentedComment #18
MacSim CreditAttribution: MacSim commentedI forget a part of the patch. Hopefully it will fix the errors from the previous tests
Comment #20
MacSim CreditAttribution: MacSim commentedIt didn't ><
Comment #27
mstrelan CreditAttribution: mstrelan at PreviousNext commentedPatch no longer applies.
Comment #28
mstrelan CreditAttribution: mstrelan at PreviousNext commentedComment #29
Ajeet Tiwari CreditAttribution: Ajeet Tiwari at OpenSense Labs for DrupalFit commentedpatch mentioned in #6 does not apply for 10.1.x. so rerolled it for 10.1.x. Sorry ignore this patch.
Comment #30
Ajeet Tiwari CreditAttribution: Ajeet Tiwari at OpenSense Labs for DrupalFit commentedpatch mentioned in #6 does not apply for 10.1.x. so rerolled it for 10.1.x.
Comment #31
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #32
Tanuj. CreditAttribution: Tanuj. as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedTried to fix CCF on #30 and other small fixes by phpcs, adding reroll for drupal 10.1.x.
Comment #33
Tanuj. CreditAttribution: Tanuj. as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedadding new patch as #32 CCF failed.
Comment #36
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedRe-roll patch required for 11.x.
Comment #37
vsujeetkumar CreditAttribution: vsujeetkumar at Srijan | A Material+ Company for Drupal India Association commentedRe-roll patch crated for 11.x.