Regarding this issue for file_entity, it's currently impossible to rename the file on upload with active fe_paths configs.

The problem is that fe_paths overwrites whatever title is provided with the token pattern set in the config rule. Shouldn't fe_paths only update the URI of the file, leaving the filename as-is when it's different from original name? This way the user specified title would be preserved.

Comments

PascalAnimateur’s picture

Title: Rename file on upload not working with fe_paths » Manual renaming of file on upload not working with fe_paths
matt.mendonca’s picture

Quick patch against 2013-09-30 dev release. Uncheck the new box on the FE paths config page to allow filename changes to file entities to saved.

sgdev’s picture

The problem I see is what is referenced in the original post (https://www.drupal.org/project/file_entity/issues/2074625).

When the file entity is initially created, editing the filename has no effect because the file does not yet exist. Either it uses the default filename, or it follows the FE Paths rules if it exists. Once the file is saved, I can re-edit the file and change the filename without issue.

Is there something else I am missing? If there was going to be a patch, I think a better way to handle would be doing this behind the scenes instead of a checkbox.

Check if there is a difference between $file->filename and the file name generated by FE Paths. If they are the same, keep going. If not, override using the $file->filename value.

sgdev’s picture

Status: Active » Needs work

I just saw this comment in the patch: "This means a user cannot rename the file entity later."

I'm not seeing that at all. Once the file entity is saved, I can edit it and change the file name to something completely different than the FE Paths default.

You might want to try upgrading to the latest version of File Entity and see if some issues are resolved, since there is a fairly new "Keep original filename" setting now available.

sgdev’s picture

Status: Needs work » Needs review
StatusFileSize
new2.33 KB

I've done some more investigation and see how this is an issue. However, there are a couple of problems with skipping $object->filename as is done in patch #2.

First, this causes the FE Paths filename settings to be ignored entirely, and just retains the original name of the file. Second, it creates a situation where the URL is rendered with an extra slash ("/") when it shouldn't be.

Attached is a slightly different patch for review. This patch does the following:

* Sets a separate checkbox option for each file type.
* Passes the checkbox values into the global FE Paths config settings.
* If the checkbox is set, re-save the file with the filename passed in through the $file object prior to returning.

sgdev’s picture

StatusFileSize
new2.38 KB

Found a bug with patch #5. The value of $config_data['override_file_entity_name'] will not be set if the file being processed is part of a custom FE Path (not one of the defaults like image, video, etc.).

Therefore need to add an extra check to see if the value isset, otherwise will display an error message.

See the attached update, thanks.