Hi! When you export an imagefield with a default image using features module, the exported code get the original fid of the default image (the default image on imagefield is stored inside the "files" table and it has a specific fid), but when you move the feature on a different installation it's quite improbable that you have the default image already stored inside the "files" table :-)
I suggest to handle the creation of the file entry on the files table when the image field is created (maybe a check could be done in order to keep updated the DB if the imagefield was already available in the destination site).
A good extra feature could be the possibility to export the image file too).
Thanks for the attention.
Comment | File | Size | Author |
---|---|---|---|
#25 | source_variable.png | 27.15 KB | robertoperuzzo |
Comments
Comment #1
hefox CreditAttribution: hefox commentedSupporting other contrib modules, unless specially stated as supporting, is generally always a feature request, in general not just features.
Comment #2
FiNeX CreditAttribution: FiNeX commentedOk @hefox, I've initially submitted this issue as a bug because the support partially works so I've thought it was considered as "supported" :-) :-) :-)
Anyway thanks for the clarification :-)
Comment #3
daveparrish CreditAttribution: daveparrish commentedI just wanted to point out that imagefield is in D7 core so it isn't really a contrib module anymore. I would also like to see features support imagefield default image in D6 and D7. Thanks.
Comment #4
mstrelan CreditAttribution: mstrelan commentedUpdating version. Could features detect the default image, export it to the feature directory and then add a hook_install that adds the image to files_managed and then use the new fid as the default? Sounds difficult.
Comment #5
mstef CreditAttribution: mstef commented+1
Comment #6
mstef CreditAttribution: mstef commentedThis looks like it may be a rough one.. since the fields now rely on file id's, rather than paths.
Perhaps the only answer is exporting the field with no default, then using hook_field_default_fields_alter() to set the default...
This is my current, weird workaround, the only thing that sucks is that it causes the feature to then be overridden:
EDIT (2): This snippet is better.. seems to be working fine.
Comment #7
wojtha CreditAttribution: wojtha commentedThanks a lot Mike.
I've made your snippet little bit more flexible
Comment #8
obrienmd CreditAttribution: obrienmd commentedHrm, doesn't seem to be working for me. I still don't see a default image set in the field UI or when a node is added w/ no image (should then render the default, right?).
Comment #9
mstef CreditAttribution: mstef commentedobrienmnd, make sure you edit the code to match your needs; field names, image names, paths, function name to make your module, etc, etc..
Comment #10
obrienmd CreditAttribution: obrienmd commentedYeah, I've been developing Drupal for a while and triple-checked all that. I think I just misunderstood how default images worked... Thanks!
Comment #11
Danny EnglanderI ran into this same issue. I uploaded my desired default image to my custom imagefield on production, cloned my live DB to my local dev and then recreated the feature locally. Once I Git pulled to production, the feature did not want to be overridden and my default image was there! I am guessing this is not ideal in many cases and obviously not very time or cost effective but it was really a one-off thing I just needed to solve quickly. I could see this getting tricky as time goes by with more than one of these types of fields.
Comment #12
blazindrop CreditAttribution: blazindrop commentedKudos to everyone that worked on this. I used a variant of the patch from comment #7 and I no longer have overrides for default_image!
+1
Comment #13
glesage CreditAttribution: glesage commentedHey guys, I've been trying to do this with the current version of Drupal (7.26) but cannot seem to get this hook to do anything...
Where can I get info about it? Google search brings up nothing... Has the naming changed?
Thanks!
Comment #14
sphism CreditAttribution: sphism commentedThanks everyone for figuring this out.
Took a while to get this working. The hook used in #7 is deprecated, now that field has been split into field bases and field instances... so:
You can swap:
mymodule_content_field_default_field_bases_alter(&$fields)
for
mymodule_content_field_default_field_instances_alter(&$fields)
just make sure you use eg : node-article-field_image .... instead of field_image (see comments in code)
Comment #15
sphism CreditAttribution: sphism commentedCaveat with #14
the if statement:
if (empty($field['settings']['default_image'])) {
...
}
seems to make this only work once, then when you clear cache, this hook fires again, and since the default image is set it does nothing.... and I end up with no default image.
Hmm... So i removed the if statement, it's working, but I guess that means i can never manually override the default image, but i've not checked because i never need to.
Comment #16
pmackay CreditAttribution: pmackay commentedI'm a bit puzzled how useful Features can be in this case, given that when uploaded the default is stored in the /files directory. Feels like for a default there should be some way to store an image in the Feature itself and reference it there, a bit like a theme references a default logo. Does that sound logical at all or am I missing something?
Comment #17
Elin Yordanov CreditAttribution: Elin Yordanov commentedSince image module is in core, this issue is not a feature request, but a bug.
Comment #18
mglaman@pmackay, that's what UUID features does - allows inline or file storage.
@pc-wurm it is not a bug because Drupal core does not support UUIDs, and the field instance utilizes a regular database 'fid'. In the same instance Features does not support UUIDs.
UUID is its own contrib and there is a UUID Features to blend the two. However, UUID features does not help accomplish this task. Should this get bumped over to UUID features to try and hijack field instance saving in the event of a default image?
Comment #19
askibinski CreditAttribution: askibinski commentedThere is a contrib solution (workaround) for this problem in D7:
https://www.drupal.org/project/default_image_ft
Comment #20
a.milkovsky#14 and #19 do not work with drupal commerce product display when images are in product entity
Comment #21
alesr CreditAttribution: alesr commentedIf you're looking for an update_hook_N() solution, here it is:
You need "default_images" folder in your custom module's root folder where you'd put MY_NEW_DEFAULT_PHOTO image file and replace the field name NAME_OF_MY_FIELD to match your field name.
Also don't forget to replace YOUR_MODULE and YOUR_MODULE_update_N with your module name and update_hook number.
Comment #22
acidaniel CreditAttribution: acidaniel commented#21 Work Like a charm @alesr ++ you made my day!!
Comment #23
tengoku@alesr solution works, however, when the feature is reverted again, the default image changes.. so that solution will not work on time.
https://www.drupal.org/project/default_image_ft works better for me.. featurizes de a variable_get/set that later on i can change in the admin form between environments
Comment #24
rreiss CreditAttribution: rreiss at Dofinity commentedThe default_image_ft module works great for me.
Sounds like a sub-module ;)
Comment #25
robertoperuzzo(#21 + #23) I merged the two solutions proposed by @alesr and @tengoku to solve their cons.
#21: as @tengoku said, when you revert the feature the default image changes
#23: you have to upload the default image (admin/content/default-image) at least one time for each environments.
With my solution you can upload and set your default image variable using hook_update_N().
First of all you have to install/enable Default image ft and set your variable name into content-type field (see the image).
Than you can create your module and add the following code into YOUR_MODULE_NAME.install file:
I improve the #21 code adding a further check
file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY)
which create the 'public://default_images' directory if it doesn't exist.
Comment #26
samgao CreditAttribution: samgao at DPCI commented#21 #23 #25 are all helpful. I know this post is supposed for D7, but you will have the same issue on D8. A few things have been changed in D8, and Default image ft module is still not available yet, so I would like to put my solution for D8 here if anyone is interested.
(1) Upload the default image, and set a Drupal variable with hook_update_N().
(2) Implements hook_entity_prepare_view().
(3) Implements hook_entity_display_build_alter(). This is only required if the image field is used as a custom view field.