The problem

Uploading file via Media upload widget never can update own file paths.
As I see, getting flag if a file need to update own path a little bit old school in D7. The File API is more complex, than a $file->timestamp == REQUEST_TIME condition could return valid value in all case. In the future, I think, this should cause errors in other modules, not only with media. If a file is fully processed before an entity is saved, this condition will never match.

Possible solution

I think, we need to track per files, if the file is processed by filefield paths.

1. Need to add a field to file_managed table, eg. ffp_processed.
2. Need to figure out, how to create a correct update method, to actualize the new field.


What data need to store in ffp_processed field? First, I set it up as a simple flag. Then I think about it, should be useful to store something else about entity, where the ffp data comes from? If yes, how to store? Only the entity id isn't enough, wee need minimum the entity type too, or instance? Store this a serialized field?

How to update existing files? Is there any always fix condition set, to determine: the file was processed by filefield path earlier?

Original issue

I don't know, this is only 2.x issue, but if I use a field with media selector widget, ffp only works, if active updateing is enabled. I don't have enough time to look into deep, but I think, in filefield_paths_filefield_paths_process_file($new, &$file, $settings, &$entity, $type, &$update) the $new is always false, because the media closes the full file uploading process.



szantog’s picture

Title:Media 2.x (or not just 2.x??) only woks if active updating checked» FFP never will work, when a file upload is fully processed before saving content
Priority:Normal» Major
Status:Active» Needs review
new4.96 KB

This is my first idea to solve this, without any update existing files.

szantog’s picture

new5.39 KB

fixed wrong field size.

Deciphered’s picture

Status:Needs review» Needs work

I'm not really certain of how to approach the issue of the Media module, technically File (Field) Paths adds the ability to process Entity tokens to a File based field based on the Entity it is attached to, so when I initially committed support for all fieldable entities and confirmed that it worked with the Media module I was confirming that a file based field attached to a File entity worked with File (Field) Paths.

A file entity itself is a different beast, as it's not necessary attached to an Entity (as it is one itself) there is not necessarily any instance to define the File (Field) Path settings nor should there necessarily be, as it may be attached to multiple entities which one should be the one that defines it's destination?

I don't even know if there is any benefit of File (Field) Paths support for Media.

I'm putting this issue back to needs work, as until I know what I want to do there can be no patch.

szantog’s picture

"I don't even know if there is any benefit of File (Field) Paths support for Media."

I thinked about this, and figured, I totally agreed. It's very difficult to decide, how should work a file entity attached to field in a node type.

My idea is, file entities need own path generation method, I've started that: If you have any advice about this, I receive it pleasure.

steinmb’s picture

Have been reading up on how to control where files are put when you upload through 'file/add' using the media module. Most threads seems to be leading here. The sandbox mention in #4 is gone, anyone know what happened with it?

ar-jan’s picture

Deciphered’s picture

Status:Needs work» Closed (won't fix)

Marking this issue as closed.

Will put a link to the File Entity Paths module on the project page ASAP.

hass’s picture

Status:Closed (won't fix)» Needs work

Is there any reason to send people to unpopular other modules with only 4 installs? I don't see any reasons for the close. Please integrate with the module here. I really run enough modules and any extra module adds more bugs to the system...

Deciphered’s picture

Status:Needs work» Closed (won't fix)


File Field Paths is a module that adds support for additional Entity based tokens to a file based field after the Entity the field attached to has been processed. Media files are entities, they do not fall inside of the this modules responsibilities. File based fields attached to a Media entity are supported, but that's as far as the support I can see in the future.

If you disagree feel free to provide me with an approach based on the existing code, or supply a patch.


hass’s picture

I'm wondering how File Entity Paths module can solve the issue, but File (Field) Paths cannot and I personally think that re-inventing the wheel every week aka duplicating logics/code is one of the worst things that can happen. Running another module just to get the job of "File (Field) Paths" solved with media module widget cannot really be true. I'm not sure what out of scope for this module here means in this context. It sounds a bit like discontinue the module File (Field) Paths in favor of File Entity Paths and this only because of a module name?!? I'm sorry, but I don't get it and the reason may be that I don't fully understand the technical difference between an Entity and a Field. :-(

Bernsch’s picture

Any news here?
It would be important if ffp would work together with the media module!

Deciphered’s picture

This issue is closed.

File Field Paths is for File fields, it will work on Media for File fields on the File entity. It won't work on the File entity itself.

I will be releasing a new module at some stage that isn't tied to File fields that will solve this issue and will become a dependency for a future version of File Field Paths.

As no one is paying for any development in this arena it's just a matter of when I have time, so no ETA on any of this.

MXT’s picture

Just an information for people who has reached this thread trough google or following all the "duplicates" in the issue queue: I've just tryed to used the suggested module but this has had a serious problem: just trying to flush the cache in my site it trigger FATAL error and breaks my site (see:

EDIT: the issue disappear using latest DEV version

MXT’s picture

Issue summary:View changes

Update description