Skip to content

Instantly share code, notes, and snippets.

@thelebster
Created May 11, 2015 14:54
Show Gist options
  • Select an option

  • Save thelebster/17dbb4198504ffa982ed to your computer and use it in GitHub Desktop.

Select an option

Save thelebster/17dbb4198504ffa982ed to your computer and use it in GitHub Desktop.
Update image field settings to use Amazon Simple Storage Service as storage.
/**
* Update image field settings to use Amazon Simple Storage Service as storage.
*/
function MYMODULE_update_7004() {
// get list of fields
$fields = field_info_fields();
foreach ($fields as $field_name => $field) {
if ($field['type'] == 'image') {
// Get the field info
$field_info = field_info_field($field_name);
foreach ($field_info['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
// Load field instance, the parameters in right order are: entity type, field name, bundle name.
$instance = field_read_instance($entity_type, $field_name, $bundle);
unset($instance['widget']['settings']['allowed_schemes']);
// updated allowed schemes
if (!in_array('s3', $instance['widget']['settings']['allowed_schemes'])) {
$instance['widget']['settings']['allowed_schemes']['s3'] = 's3';
}
// Save or update field instance.
field_update_instance($instance);
}
}
// Get a reference to the settings
$settings = &$field_info['settings'];
$settings['uri_scheme'] = 's3';
// Save the field
field_update_field($field_info);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment