This project is not covered by Drupal’s security advisory policy.

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

  1. Install module as always
  2. Set up formatter 'Image with defaults from variable' for any image field (Manage display settings of your entity)
  3. After this, module will try to find appropriate variable to retireve default image during entity render
  4. 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;
    }
  }
}


DrupalJedi Logo

Supporting organizations: 
Sponsorship

Project information

Releases