Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
It would be nice if I could put a flag in a file object that would prevent filefield paths from altering the path.
This is needed when porting data that already has a predefined path and I dont want filefield paths to touch it.
Comment | File | Size | Author |
---|---|---|---|
#17 | filefield_paths-override-field-settings-2072237-17.patch | 1.14 KB | Feng-Shui |
#10 | filefield-paths-override-settings-D7_2072237_10.patch | 1.91 KB | herved |
#6 | 2072237-override-settings.patch | 1.76 KB | Jose Reyero |
Comments
Comment #1
Deciphered CreditAttribution: Deciphered commentedTwo 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
Deciphered CreditAttribution: Deciphered commentedI may still consider this after the 1.0 release, but it's very low priority.
Comment #3
emi_bcn CreditAttribution: emi_bcn as a volunteer and 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 CreditAttribution: Jose Reyero as a volunteer and at Axel Springer España 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 CreditAttribution: 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 CreditAttribution: herved commentedHello,
Here is a D7 version.
Comment #11
mrgoodfellow CreditAttribution: 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 CreditAttribution: Feng-Shui commentedRe-roll of #13 against 8.x-1.x.
Comment #16
Feng-Shui CreditAttribution: Feng-Shui commentedUpdated to apply against 8.x-1.x again.
Comment #17
Feng-Shui CreditAttribution: Feng-Shui commentedFix PHP notice with previous patch.