Posted by japanitrat on November 23, 2008 at 4:06pm
34 followers
| Project: | ImageField |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Hi,
first of all I want to say thanks for this nice module, it absolutely rocks with imagecache. But I wonder if there is a way to assign default images to certain field instances in Drupal 6?
Comments
#1
Hello aagain.
I did a bit research on that topic and I wonder if somebody can answer me a few things:
1. Filefield seems to have some sort of default value handling for filefields, but its also not displaying any kind of setting for a default file. Because imagefield delegates the settings to filefield, maybe this default-stuff should be defined there?
2. the imagefield_field.inc (which *should* define global settings for imagefields, including default images) is never included/called. There was some discussion about moving the default file handling to the widget settings, so imagefield_field.inc gets pretty useless anyway, am I right?
3. The 2.x version of Imagefield for d5 does default images, so I peeked into that, too. Is there some reason why this was not ported to 3.x version for d6 ? If there isnt, I am going to start porting this now...
#2
subscribe
#3
The reason imagefield_file.inc never gets included is described in #340177: imagefield_image_field_settings_form not getting called
I've had a look at getting imagefield to support default images in D6, but haven't the time to have a serious go at it.
#4
desperately need this feature. subscribe.
#5
i have some sort of intermediate, quick and dirty fix which relies on CCK default value handling. I don't have the time right now to dig more into that, so it's not clean, though works on my setup. I am saying this, because the used method heavily differs from the method used in the D5 version of this module (and demands that you need to patch filefield, too). If you gonna use it, do not hit the upload button in the default-value-widget settings to save a default image. Just press save at end the field-editing form. (as I said, didnt spend much time on it).
Following patches need review and thoughts if this is the direction to go (for both of the modules). Feel free to test them.
#6
subscribe
#7
japanitrat, your patch should work on fields created before patching or only or newly created imagefileds ? Not working for me
#8
hm no it should work on all imagefields, regardless of their creation date. The corresponding fieldset is collapsed (below the help-description field in the widget settings) and easy to not get noticed.
But maybe I missed something in the patches, I'll take a look on them again later.
#9
allright, i found the reason. As I said, I am delegating the default-value handling to CCK instead of doing a custom default-value handling as in the previous versions of imagefield. The problem here is that CCK-modules in general use the default value to prepopulate the fields in the add/edit forms which leads to the result that the default value is written to the database when you save or add a new node. This essentially means that if you change the default value later on, it will not affect the nodes you've already added with the old default value (thus the old default value is still intact).
Seems like its more reasonable to *not* store the default value as normal value for new nodes, but adding a condition to the formatter functions, where default images get loaded from the field-definitions if the value is empty for that node (which also means, you will not see the default image in the edit-mode).
#10
New patch attached here. Removed the cck default value handling in favor of CONTENT_CALLBACK_CUSTOM (so basically the same as before). Additionally, I moved the stuff from imagefield_field_settings to the widget settings and instead of using filefield_field_sanitize (delegated), imagefield is now using its own sanitizing method where null-data is replaced with the proper default image.
This should work when viewing nodes, rendering views, also with imagecache if you like to. Tested on a fresh 6.8 installation, ckk 2.1, filefield 3 alpha 5, views 2.1 and imagecache 2 beta 2. The default image setting is now located below "ALT text settings" in a collapsed fieldset. You need to check "use default image" if you want to use an uploaded image as default for this widget.
Regarding to #9: default images are not written to a node's field-row, so you can change the default image for all nodes that have no image uploaded for the corresponding field. also note that you will not see default images when editing a node with empty imagefields (only showing up in output).
patch should be used on a clean imagefield 3 alpha 2 (no need to patch filefield)
#11
#12
yeah seems like default and empty values should be different in CCK eh? This patch is headed in a good direction, but there are other default value issues that should probably be resolved first before I commit this patch.
#13
Hi dopry,
which issues are you speaking of? you mean default values in CCK generally?
#14
Works! however needed one more change in function imagefield_widget
$element['#upload_validators'] += imagefield_widget_upload_validators($field);
into
if (!isset($element['#upload_validators'])) {
$element['#upload_validators'] = array();
}
$element['#upload_validators'] += imagefield_widget_upload_validators($field);
#15
I see that this patch does not put a default imagecache default value for the nodes created allready. Only for the newly created ones. Am I right? (About this I was talking before in my previous post, -sorry if it was confusing- : imagefield fields from old nodes.)
( I have a list of companies where i want a default logo for the ones that they don't have one. If i have allready a great number of companies(nodes), this patch does not help me too much. Only for newcoming company. )
#16
the new patch does work on old nodes, as mentioned in #10 (but, the old one in #5 didnt work right, as you say). Try the new one.
#17
japanitrat, thanks a lot for working on this. I've given it a pretty through review. I hope you're able to continue working on this.
it would be good if imagefield_form_alter() could only put the element on our forms. probably not a huge deal but just good behavior.
Couple of things in:
+ // critical, we override the sanitize op of filefield_field to optionally+ // display default images in nodes and views.
+ if($op == 'sanitize'){
The comment should begin with a capital letter and there should be a space before and after the ()'s.
Same goes for:
if(empty($items)){In:
+ } else $items[$delta] = $default;the else block should be on it's own line and use {} to wrap the contents:
+ }+ else {
+ $items[$delta] = $default;
+ }
This seems odd:
+ } elsereturn filefield_field($op, $node, $field, $items, $teaser, $page);
Don't just leave commented out code laying around:
+ //if (empty($items[$delta])) {+ // $items[$delta] = array('alt' => '', 'title' => '');
+ //}
+ // NOTE: doing default value here is bad, since its stored to the database then
+ // which results in a fixed value, even if we assign a new default value for that field
This isn't a proper sentence...
+//what about this default stuff instead?Add some {}s and new lines here:
++ if (empty($item['fid']) && $field['widget']['default_image']) $item = $field['widget']['default_image'];
+ if (empty($item['filepath'])) $item = array_merge($item, field_file_load($item['fid']));
Same here:
++ if (empty($item['fid']) && $field['widget']['default_image']) $item = $field['widget']['default_image'];
+ if (empty($item['filepath'])) $item = array_merge($item, field_file_load($item['fid']));
+
And again here (fix the existing one too):
+ if (empty($item['fid']) && $field['widget']['default_image']) $item = $field['widget']['default_image'];if (empty($item['filepath'])) $item = array_merge($item, field_file_load($item['fid']));
Why are you dropping these comments?:
- // If there is no image on the database, use default.Make this a proper sentence with capital letter and period.
+ //default image settingsNeed to have a space after every the comma:
+ return array('max_resolution', 'min_resolution', 'alt', 'custom_alt', 'title', 'custom_title','default_image', 'use_default_image');Remove the parens around %d:
+ form_set_error('default_image', t("The default image could not be uploaded. The destination(%d) does not exist or is not writable by the webserver.", array('%d' => dirname($dst))));Comments are not proper sentences:
+ // We save the upload here because we can't know the correct path until the file is saved.+ if (!$file = file_save_upload('default_image_upload', $validators, $dst)) {
+ // no upload to save we hope... or file_save_upload reported an error on its own.
+ return;
+ }
+
+ // set new value.
+ $form_state['values']['default_image'] = (array)$file;
+
+ // remove old image & clean up database.
Need a space after the comma:
+ return array('alt' => '', 'title' => '','default_image' => '', 'use_default_image' => '');#18
subscribe
#19
right, I made a pretty rough patch, which needs to get cleaned up, apologies.
Some of these things you mentioned already existed in the working base, others (like the code laying around) I just wanted to comment why these are not working (anymore), others are jsut results of laziness and missing language training (you may already noticed, I am not a native speaker) ;)
The imagefield code-base needs to get cleaned up as entire thing. There is a lot of code which is never called, confusing comments, and so on (also pointing to filefield). That's why I need you to check what has been written in the last year, since I focused on that just the Decembre. Thanks for looking over it, anyway, I really appreciate the activity!
More to come soon
#20
I should have made it clear that I know the current code base is really dirty. I am unfairly holding your patch to the standards that I would apply to core because I don't want to commit any more fuggly bits.
#21
Subscribe
#22
Subscribe for following this issue
#23
I hope this isn't abandoned... just like that.
I would get my hands dirty if I knew how to code but I am pretty much only able to hack according to the instructions. Leaving Drupal 5 has been too much of a leap of faith... and we are at 6.8.
Would this work on alpha4?
Thanks!
#24
uhm, I am sorry, but I didn't find time to rework the patch as suggested by drewish, yet.
Reading #10: the patch is for alpha2. I don't know if it is also applicable to alpha4. But I assume, it's not.
#25
Subscribing..
#26
Would like this feature re-added. subscribing
#27
Subcribing
#28
here's a patch that cleans up some of the trivial issues i raised in #17 but there's still more remaining
#29
cck manages to make anything a huge pain in the ass.
#30
earlier patches had moved the default image settings to the widget but--being kind of dense--i didn't understand the reasoning. the big win is that you can have a separate image for each instance of the field. it was probably also because imagefield_field.inc wasn't being called by filefield so it's hooks weren't being called. the correct name for the file is image_field.inc so i renamed it and removed all the default file code.
also turns out that the default image files were not being made permanent and would be removed during cron runs.
moved the form_alter code to file field: #370117: form_alter the field settings form so it can accept uploads
this is getting closer but please make a backup of your files and database before you try it out.
#31
Couldn't apply the last patch to alpha4 (2009-Jan-12) on my windows.(gives error: Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354).
#32
it's against -dev not the alpha.
#33
i guess i should fix the version to make that clear
#34
posted a patch on #370134: Use ImageField's default fields to update image cache to use the default images.
#35
hurm... so dopry wants to move this over to filefield and have imagefield piggy back off of it.
#36
re-rolling.
#37
hmm .. *rejoining*
is there any case where filefields should have a default file (disregarding images) ?
#38
Subscribing...
#39
There appears to be default image handling in the -dev release already, but it doesn't work (image is not uploaded and saved). It the patch at #36 newer than what's in the latest -dev release? Is it working yet?
#40
Applied last patch against last dev version and got error when trying to submit the node with the imagefield leaving the field empty: "You have error in your sql sintax... the value of the field ... can't be NULL".
#41
I too just applied the patch and can confirm the problem.
#42
subscribe..
I've tried the last -dev (without patching it): when I try to upload the default image, the folder is created, but no image is uploaded.
#43
Subcribing...
I'm able to try it on alpha 4 but I red it's not working so I'll wait for newer patches...
#44
I'd like to get this in also, but at the widget level rather than the field level. This patch will need serious reworking after #397578: Uncouple ImageField from FileField Custom Hooks, which I want to get in as soon as possible.
#45
mhjup, on widget level most def. (where default values usually are, afaik)
#46
Also regarding:
I can't think of any practical usage. I'd prefer this was part of ImageField rather FileField. Since we'll be implementing it at the widget level, especially after #397578: Uncouple ImageField from FileField Custom Hooks, we'll definitely be including this in ImageField rather than FileField.
#47
subscribe :)
#48
subscribing
#49
subscribing
#50
is there any solution for :
Default value in imagefield
Refer following URL for more details:
http://drupal.org/node/403306
#51
subscribe
#52
subscribe
#53
*sigh* we already had it working, once :D
#54
Okay, thinking about this some more, it's actually really difficult to store this at the widget level, since when you display the data (say in Views or just in the normal node), you don't usually have information about which "widget" was used, so storing this at the widget level doesn't work well because we don't actually know which widget is being used for each field at display time.
Soooo, I think we should go back to the field implementation. Since ImageField is now entirely dependent on FileField's field, we'll indeed have to add "Default file" to FileField, even though 99% of the time people will only use this for default images.
#55
subscribing
#56
Here's a stab at a port of the patch drewish posted in #36. This implements a default image at the widget level within ImageField. However, now that ImageField no longer manages its own field, there's no way to add this image on output, so a modification to FileField also has to be made. I'm not sure I like this special exception just for ImageField.
The options:
Attached are patches for both ImageField and FileField.
#57
I've committed the attached version of the patch. I decided to leave this functionality at the widget level in ImageField since it's where I thought it made the most sense. The attached version of the patch is the same as #56, only it also includes an upgrade path for users upgrading from Drupal 5.
#58
Subscribing...
#59
humm... this doesn't seem to be working. i can assign the default image but doesn't seem to be used by all the formatters... do other modules need to make a change to use this?
#60
They shouldn't need to be updated, it should work right away with all Formatters since the change is in the "sanitize" operation that happens just before formatters are called. I tested it just fine with ImageCache and with the formatters provided by ImageField.
#61
oh, just needed to make sure my formatter accepted filefield rather than image.
#62
After applying latest patch my imagefield options disappeared from CCK fields administer pages.
#63
subscribing
downloaded 3.x-dev March 26. I'm getting the Default image settings option, but it doesn't look like the image I specify is being saved--it doesn't show up in my test CCK, and when I go back into field management for my CCK type, the Default image in my image field is blank.
#64
everyone needs to make sure that they run the update.php script.
#65
I downloaded http://ftp.drupal.org/files/projects/imagefield-6.x-3.0-beta3.tar.gz, and ran the update script, but despite searching I can't find any interface for adding a default image. Is this after adding a new Filefield to a CCK type using the Image widget, or is there some other place that holds the preferences for default images?
Perhaps this was because I skipped beta2?
#66
glass.dimly, don't worry you didn't do anything wrong. This feature hasn't been included in an official release yet, it's only in the development version. You can download it by clicking "View all releases" from the project page and downloading the 6.x-3.x-dev version.
#67
Is it compatible with ImageFupload ? I'm using this module in combination with ImageField, currently working only with the last alpha version. I'd like to have the default image working too...
#68
Probably not currently yet since it was just added to ImageField. However there's no reason why ImageFupload can't leverage the default image since it builds on top of the normal ImageField widget.
#69
Heilong: See #412640: Provide Compatibility With New ImageField 3.x (RC versions).
#70
Downloaded the 6.x-3.x-dev version, updated my drupal installation (updates 6003, 6004, ... were done for imagefield). The field for uploading default image and checkbox "Use default image" appeared. I set the checkbox to ON and uploaded my default image for my content type. Then I go to the existed node of this content type with the imagefield left empty when it was created and there is no default picture. I've updated the node and no default picture again. Created new node of the type without image and default image didn't appear again. Is this functionality allready in dev version or it's not?
Thanks!
#71
Make sure you download the 3.x-dev version of both FileField and ImageField. Changes to FileField were necessary to actually output the image.
#72
Thanks for your help, quicksketch, everything is working fine!
#73
I have a small paying job that may require the ImageField "patch" that is mentioned on this forum. Please contact me for more details. I would like to get this done ASAP. We just can't make it work on a specific site that we have.
#74
pinwheelmedia, you don't need a patch, you just need to update to the RC1 versions of ImageField and FileField.
#75
rc1 of BOTH modules works as advertised for me.
Thanks quicksketch! This rocks, and the effort is appreciated!
salud,
Sunset Bill
#76
Thanks so much Quicksketch! I'll pass it along to my developer to see if he can make it work. If by any reason we are able to fix the issue. Would you be interested in helping us? Thanks again!
#77
Should the default images work with Views also?
I've upgraded to both Filefield and Imagefield RC1, defined a default Image for content type 'News', but the default image does not show in my Views listing (nor in the full node view).
If it's supposed to work with Views I should look for other causes...
#78
Yep it's strange. It's working for me but not with all views... I don't know why...
#79
I found the problem: if you re-use an imagefield in another content type, that field also gets a new label in that content type. Views appears to use the latest label for the field, instead of the label for the specific content type.
When I removed the second instance of my imagefield, the default images immediately showed for the original content type.
Oh well, I found a Views issue on this #432150: View shows CCK Field key instead of label, it actually being a CCK bug that is fixed in -dev.
I guess all should work with latest CCK -dev, not tested.
#80
oh ok, thanks :)
But is it fix for you? because i'm usiong the dev. version of CCK.
#81
Well I made a new imagefield, instead of using the same imagefield twice in different content types. So it works for me.
From what I read it should be working when using the imagefield in different content types, at least with the latest -dev. Have you updated your CCK?
#82
yep, I do... I'm going to investigate myself :)
This is only Thumbnails who are not displaying for one node type in views.
Thumbnails default images work well with another node type.
#83
Automatically closed -- issue fixed for 2 weeks with no activity.