Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there any reason the file_entity_add_upload_step_fields() step of the uploading process doesn't allow the user to edit the filename (not the filename on disk, but the title of the entity)?
It seems to me that this, along with the destination, user info, and anything else attached to the file edit form should be editable here just as it is when loaded via file_entity_edit().
Comments
Comment #1
Dave ReidIt doesn't exist because it hasn't been written yet. This is a new feature, so re-categorizing.
Comment #2
azinck CreditAttribution: azinck commentedWorking on a patch for this. Here's a question: right now we only show the file_entity_add_upload_step_fields() form if there are fields attached to the entity. As of now, this makes sense since that form only lets you edit attached fields. If we add the ability to edit the entity title and other entity-related properties then perhaps we should *always* show that step of the upload process. Does that make sense to people?
Comment #3
azinck CreditAttribution: azinck commentedHere's an initial stab at it. I retained the logic that I was asking about in #2 that skips the final step if there are no fields attached to the entity type. We may wish to change that.
Comment #4
hefox CreditAttribution: hefox commentedWhy remove the preview?
Comment #5
azinck CreditAttribution: azinck commented@hefox: I was trying to keep it as close to the current functionality as possible, but add the ability to edit the fields.
Comment #6
aaron CreditAttribution: aaron commentedThis looks like a good start. However, I notice that when you have private files enabled, that the new form element does not appear.
Comment #7
Devin Carlson CreditAttribution: Devin Carlson commentedMarked #2091443: No option to rename file after upload as a duplicate.
Comment #8
Devin Carlson CreditAttribution: Devin Carlson commentedMarked #2090889: rename file during upload (filesystem- name) as a duplicate.
Comment #9
RyanPrice CreditAttribution: RyanPrice commentedPatch in #3 isn't showing the rename option for me. Are there certain permissions or settings that need to be set for this?
My situation is a simple file upload where the name of the file is defaulting the filename and we need to be able to change it to something that makes more sense. I've applied the patch but its still skipping that step for me.
Comment #10
azinck CreditAttribution: azinck commentedHere's a patch updated to never skip the editing step (even if there are no fields attached to the entity). Should fix RyanPrice's issue in #9.
Comment #11
PascalAnimateur CreditAttribution: PascalAnimateur commentedI'm also looking into this issue as I really want my users to be able to rename their files on initial upload.
From what I can see, the problem lies around line 380 of file_entity.pages.inc in function file_entity_add_upload_submit :
Upon inspection, $file->filename changes from the correct user-entered title to the raw filename because of this entity_form_submit_build_entity function call.
The way I see it, the option "Skip available fields" should be split into "Skip manual title override" and "Skip available fields" (but could still be processed in a single step on the multiform).
Comment #12
azinck CreditAttribution: azinck commented@PascalAnimateur: have you tried my patch in #10? It always lets you set the filename on upload.
To be clear, though, this only lets you set the filename property, not the actual name of the file on disk. The name of the file on disk is managed by Drupal to avoid collisions and we don't attempt to set it or override it ourselves.
Comment #13
PascalAnimateur CreditAttribution: PascalAnimateur commented@azinck Yes I did try your patch... I was already able to change the filename field on step 3 of the upload form before patching, but it didn't save it, reverting to the transliterated original filename. I was hoping your patch would fix that and make the form save the filename but it doesn't in my case.
Should I point out that I'm using Media 2.x with PathAuto and FileEntity Paths ?
Comment #14
azinck CreditAttribution: azinck commented@PascalAnimateur: Please clarify if you're trying to edit the name of the file on disk, or the name of the file in Drupal. In comment #11 you mention $file->filename. The patch in #10 will allow you to always edit the filename on upload but it does not affect the actual name of the file on disk (which is stored in $file->uri).
Comment #15
PascalAnimateur CreditAttribution: PascalAnimateur commentedI'm not trying to edit the filename on disk.. just the name of the file as it appears on /admin/content/file or file/
Comment #16
azinck CreditAttribution: azinck commentedI just tested this with the latest dev of media and file entity and it's working fine for me. Is anyone else having PascalAnimateur's problem?
Comment #17
PascalAnimateur CreditAttribution: PascalAnimateur commentedI found what caused the problem: it turns out I had a File Entity Path config that used [file:name-only-original].[file:extension-original] as a replacement pattern and this overwrites both the URI and the filename of the entity.
Thanks so much for the help ! I've submit this as a new issue for fe_paths.
Comment #18
RyanPrice CreditAttribution: RyanPrice commentedPatch #10 worked for me.
Comment #19
RyanPrice CreditAttribution: RyanPrice commentedComment #20
azinck CreditAttribution: azinck commented#6 points out an issue with private files which I haven't yet looked at, so this still needs work.
Comment #21
mtoscano CreditAttribution: mtoscano commentedThe patch conflict with Transliteration module, if the option to clean name during uploads it is active.
Transliteration should take care only of the actual file name in the directory and this patch should instead take care of the name of the file in the database, but something goes wrong.
Thanks for the patch anyway.
Comment #22
RyanPrice CreditAttribution: RyanPrice as a volunteer commentedIs there any update on this functionality making it into the media module either through this thread or another one that I may not have found? Just hoping someone who keeps a closer eye on this module might have an update.
Thanks.
Comment #23
discipolo CreditAttribution: discipolo commentedhere is a reroll against current dev
i cannot confirm the problems mentioned in #6 this patch works great for me.
Comment #24
Devin Carlson CreditAttribution: Devin Carlson as a volunteer commentedComment #28
discipolo CreditAttribution: discipolo commentedthe tests fail due to Notice: Undefined index: #field_name in file_managed_file_save_upload() (line 661 of /var/www/SHOEP/commerce_deploy/modules/file/file.module). which can be fixed with #1903010: Notice: Undefined index: #field_name in file_managed_file_save_upload()
Comment #29
MrPaulDriver CreditAttribution: MrPaulDriver commentedI think this facility needs to come with it own permission. Edit filename.
I am quite certain that some editors will confuse the filename with the description during upload and inadvertently remove the file extension. This would prevent the opening of a file by the browser or the application defaults on their computer.
A developer would probably not make this mistake but a human might.
Comment #30
azinck CreditAttribution: azinck commented@MrPaulDriver: I'm not clear on what your saying. This patch does not let you edit the actual name of the file that served up by the server. Just the "name" property which is metadata of the file.
Comment #31
Ajrahul CreditAttribution: Ajrahul as a volunteer and at Srijan | A Material+ Company commented@azinck: Patch #10 works for me. Is it possible to allow special characters when new title is added for Patch 10.
Comment #32
FiNeX CreditAttribution: FiNeX as a volunteer commentedWould be possible to change the file system name too? A simple way to solve #29 should be appending the correct extension (using the mime type) if the extension is missing or is wrong.
Comment #33
panche CreditAttribution: panche as a volunteer commentedHi, I think using something like
file_move
function would be greatly appreciated in this solution.If the content manager needs to change the URL (and Drupal's URI) of the served file so it makes more sense for crawlers like Google's, this fits perfectly here.
Comment #34
joseph.olstadRerolled patch, (it needed it, hunk 2 was failing)
Despite the forthcomming simpletest test fails, patch should probably still be good.
Expect some undefined index test errors from core due to:
#1903010: Notice: Undefined index: #field_name in file_managed_file_save_upload()
which co-incidentally, a D7 core patch is available.
Comment #36
joseph.olstadpostponed until
#1903010: Notice: Undefined index: #field_name in file_managed_file_save_upload()