The managed_file FormElement (Drupal\file\Element\ManagedFile) valueCallback implementation calls file_managed_file_save_upload($element, $form_state) which calls _file_save_upload_from_form($element, $form_state). The default value for $replace is FILE_EXISTS_RENAME. It would be nice if the element provided an attribute that allows us to specify what we want the behavior to be.
Suggestion: Add a new attribute to the element #file_exists_behavior, retrieve that value in valueCallback, modify file_managed_file_save_upload to accept the argument (with a default value of FILE_EXISTS_RENAME) and pass it along to _file_save_upload_from_form.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 3012457-16.patch | 3.23 KB | nikhil_110 |
| #15 | 3012457-nr-bot.txt | 169 bytes | needs-review-queue-bot |
| #11 | After patch 2.png | 150.46 KB | mitthukumawat |
| #11 | After patch 1.png | 87.9 KB | mitthukumawat |
| #9 | allow_FILE_EXISTS_REPLACE-3012457-9.patch | 3.22 KB | piyuesh23 |
Comments
Comment #2
vegantriathleteComment #3
vegantriathleteComment #4
idebr commentedRelated to / possible duplicate of #2648816: Uploaded files are impossible to replace
Comment #9
piyuesh23 commentedAttaching an updated patch for Drupal 9.1.x.
Comment #11
mitthukumawat commentedPatch #9 applied cleanly on drupal 9.3.x-dev. Adding screenshots of diff for reference. Thanks for the patch.
Comment #15
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or 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 #16
nikhil_110 commentedAttached patch against Drupal 10.1.x
Comment #17
nikhil_110 commentedComment #18
smustgrave commentedThis seems like it could use an issue summary update.
Also test coverage will be needed.