Add support for ImageField
drupaloSa - August 17, 2008 - 16:49
| Project: | FileField Paths |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Deciphered |
| Status: | closed |
Description
I enable this module and go to edit an imagefield. But under the Path Settings, i see only the User and Global tokens. There aren't any node tokens or file name configuration. Btw, i'm using Filefield 6.x-3.0 alpha 3.

#1
It's likely that ImageField is the issue as the module was written before there was a usable ImageField module.
The module should work with a standard FileField field.
I will look into this further as soon as possible.
#2
#3
ok, i'll be waiting your response.
#4
Here's a patch that adds support for ImageField.
Will commit to HEAD when I get a chance.
#5
Initial code committed to HEAD.
#6
Thanks, i'll try this asap.
#7
1. I've tried different path settings such as [nid], [type], [yyyy] and [yy]. Once the image is uploaded a folder is created. But it's named wrongly, e.g. [yyyy]. When the node is saved, then a second folder is created but this time it's correctly named, e.g. 2008. The image file is put in the second folder where as the thumb image stays in the first. Also i get a couple of the following warning messages:
# warning: preg_match() expects parameter 2 to be string, array given in E:\Program Files\xampp\htdocs\d63\sites\all\modules\transliteration\transliteration.inc on line 53.
# warning: mb_eregi_replace() expects parameter 3 to be string, array given in E:\Program Files\xampp\htdocs\d63\sites\all\modules\pathauto\pathauto.inc on line 228.
I tried this using all three file path cleanup settings on and off. Nothing changes.
2. Filename information resets to the default every time the field info is edited.
#8
and a third one.
3. Thumbnail image name doesn't match the renamed file, so the next time your edit the node it cannot be displayed.
#9
@drupaloSa
1. Due to node tokens not being populated until the node has been saved, the [yyyy] folder behaviour is the only way this can work. As you noticed yourself the file is moved from the temporary [yyyy] folder to the 2008 folder when the node is saved/updated.
The thumbnail isn't supported yet, I still have to look into a simple way to support it. My main concern is that there may be other Filefield widgets like ImageField down the track and I don't want to have to make an exception for each widget, but unless I can find a generic solution it may be the only way to go.
As for the errors you're getting, can you tell me what versions of the Transliteration module and the Pathauto module you are using? Have you used these modules successfully before using them in conjunction with FileField Paths?
To test the Transliteration integration you will need a filename, page title, token, etc with unicode characters such as those found in #290347: Integration with transliterateration module.
To test the Pathauto integration you will need a filename, page title, token, etc with words or punctuation set to be filtered in your Pathauto settings.
To test the lower case conversion you simply need a file with upper case characters.
2. Please clarify this point for me, when you say 'Filename information' and 'field info', what specifically are you talking about? Do you mean that the Filename isn't being renamed as per the pattern defined in the ImageField settings?
3. This is related to your first point, thumbnails are not yet supported.
I should have made it more clear when I committed this code, it is still developmental, while it does achieve the primary goal (move and rename the actual image file), it will be changed when I work out a solution I am happier with.
#10
I know it's not ready for productions sites yet and i'll be glad if i could help to identify any possible bugs.
1. I'll make some tests later but for now i can say that i had pathauto (6.x-2.x-dev) and transliteration (6.x-2.0) modules installed before trying filefield path module. I didn't have any problems while uploading files.
2. The default filename is [filefield_paths-name].[filefield_paths-ext]. I change this to [nid]-[filefield-fid]-[title].[filefield_paths-ext] and save. When i go to edit this CCK field again, the filename expression reverts back to default, i.e. [filefield_paths-name].[filefield_paths-ext].
#11
@drupaloSa
Don't get me wrong, I really do appreciate the bugs, it proves that someone actually uses my module :)
1. I just ran a test with Pathauto 2.x and didn't get any errors, will do another test in a bit with the Transliteration module installed as well. It might be related to you running on a Windows environment, I will try to get a Windows test server running this weekend.
2. Bug confirmed, will commit a fix to HEAD tonight, but for the moment you can fix it yourself by making the following change:
Change line #21 of filefield_paths.module from this:
'filefield_paths_'. $form['type_name']['#value'] .'_'. $form['field_name']['#value'] .'_filename',to this:
'filefield_paths_'. $form['type_name']['#value'] .'_'. $form['field_name']['#value'] .'_file_name',#12
Ran another test with both Pathauto and Transliteration installed and enabled for cleanup and the I got the expected results, no errors.
I will try to get a windows environment up over the next few days and test that way.
#13
I just wanted to add that I am using this module, and think it is great and look forward to support for the imagefield thumbnails.
Thanks for all of your hard work.
#14
@kmadel
Thank you, it's always nice to get positive feedback.
#15
Heres a patch to add ImageField Thumbnail support.
Code will be added to the next dev version which is due out soon.
#16
Committed to HEAD.
#17
Thanks Deciphered, recently i didn't have the time to test the latest code. I'll try when i get the chance.
#18
Automatically closed -- issue fixed for two weeks with no activity.