Problem/Motivation
I would like to use Taxonomy terms as folders (using Media directories.
If these terms have hierarchy, this hierarchy should be applied accordingly to the folder structure.
Example:
Term A
--Term B
----Term C
Folder structure should be -> a/b/c/file.txt
My plan is to use tokens for the parents like that:
[media:directory:entity:parents]/[media:directory:entity]
The problem is that the token replacement returns parents comma,separated - "a, b, c"
Proposed resolution
I've created a small patch that just replaces these commas with slashes, so that the terms can be used as part of the path.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | taxonomy-hierarchy-folders-3182718-1.patch | 538 bytes | yivanov |
Issue fork filefield_paths-3182718
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
yivanov commentedComment #3
megachrizI wonder if this is the prefered way to fix this issue. What happens for example if you base the file path on the node title, and then use a comma in that title? I think that in such case you don't want the file to go into a subdirectory.
Example:
[node:title].The file would then go into good/bad-and-ugly, which doesn't make sense in this context.
I think a better solution would be to use a token that returns the terms slash separated instead of comma separated.
Comment #4
yivanov commentedThanks for your feedback, @MegaChriz.
Indeed you are right that this solution is not the best one and doesn't cover all the cases.
The main reason I added this patch is to cover my specific case and start a discussion on how this can be improved on a module level.
Do you think creating this custom token should be handled in this module or it's out of scope and each project should prepare such if they want to achieve the above case?
Another thing that comes to my mind is to use the options array and pass the join parameter there like this:
The token replacement logic accepts it:
Then we can have a settings checkbox that says "Replace commas with slashes", similar to the "Remove slashes (/) from tokens" setting.
Comment #5
vivify commentedCould you use join paths? Similar to [term:vocabulary]/[term:parents:join-path]/[term:name]
Comment #6
marcoka commentedThis looks very interestig.
@vicify
Are taxonomy terms avaliable? I can only see user tokens.
Comment #7
volegerComment #9
igoragatti commentedI've re-applied the changes so the patch continues to work.