Skip to content

Instantly share code, notes, and snippets.

@juliquiron
Created February 9, 2016 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliquiron/b5c287a1a1d2593d9373 to your computer and use it in GitHub Desktop.
Save juliquiron/b5c287a1a1d2593d9373 to your computer and use it in GitHub Desktop.
Default dummy image for Drupal 7 tutorial #6
/**
* Implements hook_field_create_instance().
*/
function MY_DEPLOY_MODULE_field_create_instance($field) {
if($field['field_name'] == 'field_imagen') {
$source = drupal_get_path('module', 'MY_DEPLOY_MODULE') . '/dummy.jpg';
$file = new stdClass;
$file­>filename = 'dummy.jpg';
$file­>timestamp = REQUEST_TIME;
$file­>uri = $source;
$file­>filemime = file_get_mimetype($source);
$file­>uid = 1;
$file­>status = 1;
$file = file_copy($file, 'public://default.jpg', FILE_EXISTS_REPLACE);
$fid = $file­>fid;
$field = field_info_field("field_imagen");
$field['settings']['default_image'] = $fid;
field_update_field($field);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment