Image formatter default variable
Component ID
2692673
Component name
Image formatter default variable
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
139
Component created
Component changed
Component body
Summary
The purpose of this module to provide default values when your render image fields when nothing was uploaded.
The generic problem of default behaviour is that default value stored as file id and that's why could not be successfully stored in features and maintained across environments.
In the other hand, this module is similar to Image default image formatter module.
But rather than 'Image default image formatter', current module allow to set up an URI of default file per formatter instead of file upload (which is still relies on the file id). It helps to have a consistent value among environments and have 'default' status for features. Forget about missed default values after features revert.
Usage
- Install module as always
- Set up formatter 'Image with defaults from variable' for any image field (Manage display settings of your entity)
- After this, module will try to find appropriate variable to retireve default image during entity render
- Set up variable via image_formatter_default_variable_set() function. It's possible to specify granularity of default value per field, entity or view mode.
Example
function YOUR_MODULE_themes_enabled($theme_list) {
foreach ($theme_list as $theme) {
if ($theme === YOUR_THEME) {
$source = drupal_get_path('theme', YOUR_THEME) . '/img/default-avatar.png';
$destination = 'public://default-avatar.png';
if (file_unmanaged_copy($source, $destination, FILE_EXISTS_REPLACE)) {
image_formatter_default_variable_set('field_image', 'user', NULL, $destination);
}
break;
}
}
}

