As far as I know the only way to use a default image for a image field is by uploading one. This functionality is great for user that only use one site environment or don't do any development/style work on their site, but when you are working with a team and use a local, development, stage, and production environment and keep all your configuration into features, the option of uploading a file is pointless.

I rather see something similar to what is happening under the account settings (/admin/config/people/accounts) where you actually can specify a path for your default image. Or even better a combination of both, something like this:

/**
 * Implements hook_field_settings_form().
 */
function image_field_settings_form($field, $instance) {
  $defaults = field_info_field_settings($field['type']);
  $settings = array_merge($defaults, $field['settings']);

  $scheme_options = array();
  foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {
    $scheme_options[$scheme] = $stream_wrapper['name'];
  }
  $form['uri_scheme'] = array(
    '#type' => 'radios',
    '#title' => t('Upload destination'),
    '#options' => $scheme_options,
    '#default_value' => $settings['uri_scheme'],
    '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'),
  );

  // When the user sets the scheme on the UI, even for the first time, it's
  // updating a field because fields are created on the "Manage fields"
  // page. So image_field_update_field() can handle this change.
  $form['default_image'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default image'),
    '#description' => t('If no image is uploaded, this image will be shown on display. If "Specific path" field is not empty then this value will be used even if a file has been uploaded in the other field.'),
  );
  
  $form['default_image']['upload_file'] = array(
    '#title' => t('Upload file'),
    '#type' => 'managed_file',
    '#default_value' => $field['settings']['default_image'],
    '#upload_location' => $settings['uri_scheme'] . '://default_images/',
  );

  $form['default_image']['set_path'] = array(
    '#title' => t('Specific path'),
    '#type' => 'textfield',
    '#default_value' => ($field['settings']['default_image'] != 0) ? $field['settings']['default_image'] : '',
  );

  return $form;
}

If I work on this approach for Drupal 7 there is any chance that get accepted?

For sure I'm not the only one that has run into this problem, and we have talked about using a form alter to archive this but then we would have to do the same on every project we work on; then the next question is, is there a module out there that does this?

Thanks a lot for your help.

Comments

altrugon’s picture

After more re-search on this I found #1308860: Allow modules to alter fields settings hook and hook_field_prepare_view but it looks like none of the options are reachable from outside the module.

At this point I'm starting to think that Image field is not alterable at all.

mrfelton’s picture

I suppose we would need something similar to http://drupal.org/project/field_formatter_settings but that gives the ability to edit/add to the field settings form.

Version: 7.7 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.