Needs review
Project:
File (Field) Paths
Version:
8.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
22 Aug 2013 at 23:32 UTC
Updated:
22 Jun 2026 at 06:12 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
decipheredTwo simple solutions (IMO):
Not the greatest options, but doable. I'm sure there's even easier solutions, but I'm not putting much thought into it right at this second.
With that said, I think it's a valid request, and I will try to look at it in the near future. Patches welcome of course.
Cheers,
Deciphered.
Comment #2
decipheredI may still consider this after the 1.0 release, but it's very low priority.
Comment #3
emi_bcn commentedHi there,
I'm creating programmatically lots of nodes from a migration. I would like FilePaths to work correctly, but to disable _filefield_paths_replace_path on node content. I mean, I need FileField to generate the final alias for the files, but I will be doing preg_replace on content on a later phase of the migration. Any simple solution (IMO) for this? Is it acceptable the petition?
Thanks a lot for the great work you do here!!
emi
Comment #4
jonhattanAlternatives exposed in #1 are valid ones for Drupal 7. Even in Drupal 8 I managed to temporarily disable the filefield_path config while migrations are running. FYI I used this snippet:
Problem is that updating a field config this way invalidates this cache tags: token_info, config:field.field.media.image.field_media_image, entity_field_info, media_view, views_data....
Those tags are generic enough to purge caches of almost all site pages. In our case, because the way we use migrations, we're purging caches at a high frecuency on a daily basis.
Comment #5
jonhattanOk, there's another way to do this: alter the settings after loading the config entity, by implementing hook_field_config_load(). This requires a module, and is trickier to check if a migration is running.
Comment #6
jose reyero commentedHere's a patch, an ugly workaround, yes, but...
Comment #7
geek-merlinI think it's not that ugly and the code is nice and straightforward. I'd give green lights.
Comment #8
nwom commentedA port of #6 to D7 would be great as well for those of us on D7.
Comment #9
geek-merlinHmm, if $entity->fielfield_paths_override_settings is NOT an array, this will give hard to track results. We should check for that and throw something meaningfurl (imho preferred) or silently ignore.
Comment #10
herved commentedHello,
Here is a D7 version.
Comment #11
mrgoodfellow commentedHey guys! I'm needing the same functionality only I would like to simply alter the way the file is re-written ONLY and not effect any other options.
In my configuration I have: [file:ffp-name-only-original][random:hash:crc32].[file:ffp-extension-original]
which adds a random hash to my file name.
essentially I would like to create a hook that will redefine this value to:
$form['instance']['settings']['filefield_paths']['file_name']['value'] = '[file:ffp-name-only-original].[file:ffp-extension-original]';
currently my function looks like:
This would remove the random hash on published files but allow it to remain on drafted files.
function MYMODULE_workbench_moderation_transition($node, $old_state, $new_state) {
if ($node->type == 'document' && $new_state == "published") {
$form['instance']['settings']['filefield_paths']['file_name']['value'] = '[file:ffp-name-only-original].[file:ffp-extension-original]';
}
When I use this function I get an error Is there a better way to accomplish this in MYMODULE?
Basically I want to modify the way the file name is re-written, not disable the functionality of the module completely.
Comment #12
hussainwebThe code snippets in comments #4 and #5 don't work anymore (Drupal 8.6, Drush 9.4). I adapted the code in an event subscriber instead. Here's the snippet:
The code should be self explanatory. It's a little beyond scope of this issue but this also shows how to disable geocoding during migrations.
To register the event subscribed, here is the snippet from the services.yml file.
Comment #13
trebormcI created a patch similar to # 6. Thanks @Jose
Now for each field in the migration you can overwrite. For example:
Comment #14
ultimike@hussainweb's code above in #12 is +1!
Saved me a bunch of time - thank you!
-mike
Comment #15
feng-shui commentedRe-roll of #13 against 8.x-1.x.
Comment #16
feng-shui commentedUpdated to apply against 8.x-1.x again.
Comment #17
feng-shui commentedFix PHP notice with previous patch.
Comment #18
vistree commented@feng-shui,
should your patch still work for Drupal 10.4 and filefield_paths 8.x-1.0-beta8?
The patch still applies - but it seems to be ignored on my media migrations.
I tried to debug and it seems that function filefield_paths_entity_update() from filefield_paths.module is not called?!
Comment #20
rudolfbykerRe-rolled the patch for
1.0-rc1Comment #22
rudolfbykerOpened a merge request to solve this properly. Please review :)
Comment #23
rudolfbykerThe tests seem to pass for the current and previous major versions of Drupal. They did not run for the "next major version", because
composer installfailed, which is not within the scope of this issue to fix.Comment #24
liam morlandComment #27
decipheredImplemented a hybrid of the two approaches already on this issue, plus the older idea from comment #9, rather than picking one.
Three levels of control now exist:
enabledkey infilefield_paths.settingsconfig (same idea as MR !62, rebased onto current 8.x-1.x). Shows a status report warning if left disabled, so it doesn't get forgotten about.filefield_paths_settingsproperty on the entity, read once per save and merged into the settings passed tohook_filefield_paths_process_file(). Never persisted, so no config save and no cache invalidation.Examples of the per-save override:
This generalises comment #9's
$entity->fielfield_paths_override_settingsidea rather than the per-field-item-value approach from the more recent patch, since it doesn't require touching every field separately to disable more than one.MR: !70. Patch also attached for anyone who prefers to review/test that way.
Credit to jose reyero, geek-merlin, nwom, herved, hussainweb, trebormc and feng-shui for the patches this builds on, and to rudolfbyker for the two recent attempts.