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().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Category: bug » feature

It doesn't exist because it hasn't been written yet. This is a new feature, so re-categorizing.

azinck’s picture

Working 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?

azinck’s picture

Status: Active » Needs review
FileSize
4.59 KB

Here'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.

hefox’s picture

Why remove the preview?

azinck’s picture

@hefox: I was trying to keep it as close to the current functionality as possible, but add the ability to edit the fields.

aaron’s picture

Status: Needs review » Needs work

This looks like a good start. However, I notice that when you have private files enabled, that the new form element does not appear.

Devin Carlson’s picture

Devin Carlson’s picture

RyanPrice’s picture

Patch 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.

azinck’s picture

Here'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.

PascalAnimateur’s picture

I'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 :

// Save the form fields.
// Keep in mind that the values for the Field API fields must be in
// $form_state['values'] and not in ['storage']. This is true as long as
// the fields are on the last page of the multi step form.
entity_form_submit_build_entity('file', $file, $form, $form_state);

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).

azinck’s picture

@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.

PascalAnimateur’s picture

@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 ?

azinck’s picture

@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).

PascalAnimateur’s picture

I'm not trying to edit the filename on disk.. just the name of the file as it appears on /admin/content/file or file/

azinck’s picture

I 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?

PascalAnimateur’s picture

I 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.

RyanPrice’s picture

Patch #10 worked for me.

RyanPrice’s picture

Status: Needs work » Reviewed & tested by the community
azinck’s picture

Status: Reviewed & tested by the community » Needs work

#6 points out an issue with private files which I haven't yet looked at, so this still needs work.

mtoscano’s picture

The 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.

RyanPrice’s picture

Is 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.

discipolo’s picture

here is a reroll against current dev
i cannot confirm the problems mentioned in #6 this patch works great for me.

Devin Carlson’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: allow_filename_and-2074625-23.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: allow_filename_and-2074625-23.patch, failed testing.

discipolo’s picture

Status: Needs work » Needs review
Related issues: +#1903010: Notice: Undefined index: #field_name in file_managed_file_save_upload()

the 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()

MrPaulDriver’s picture

I 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.

azinck’s picture

@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.

Ajrahul’s picture

@azinck: Patch #10 works for me. Is it possible to allow special characters when new title is added for Patch 10.

FiNeX’s picture

Would 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.

panche’s picture

Hi, 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.

joseph.olstad’s picture

Rerolled 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.

Status: Needs review » Needs work

The last submitted patch, 34: file_entity-allow_filename_and-2074625-34.patch, failed testing.

joseph.olstad’s picture