function imagefield_crop_update_7302 in Imagefield Crop 7.3
Upgrade Imagecrop preset to use machine name
File
- ./
imagefield_crop.install, line 321 - Module installation file.
Code
function imagefield_crop_update_7302() {
if (!db_field_exists('imagefield_crop_preset', 'label')) {
db_add_field('imagefield_crop_preset', 'label', array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
db_query('UPDATE imagefield_crop_preset cp SET cp.label = cp.name');
}
foreach (field_info_fields() as $fname => $info) {
if ($info['type'] == 'imagefield_crop') {
foreach ($info['bundles'] as $type => $bundles) {
foreach ($bundles as $bundle) {
$instance = field_info_instance($type, $fname, $bundle);
$new_presets = array();
foreach ($instance['widget']['settings']['presets'] as $pid => $preset_name) {
if (is_int($pid)) {
$preset = imagefield_crop_preset_load($pid);
$new_presets[$preset->name] = $preset->label;
}
else {
$new_presets[$preset_name] = $preset_name;
}
}
$instance['widget']['settings']['presets'] = $new_presets;
field_update_instance($instance);
}
}
}
}
}