Created
May 11, 2015 14:54
-
-
Save thelebster/17dbb4198504ffa982ed to your computer and use it in GitHub Desktop.
Update image field settings to use Amazon Simple Storage Service as storage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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