function _manualcrop_update_style_name_in_field_widget in Manual Crop 7
Update or remove a style name in all Manual Crop field widgets.
Parameters
$style_name: Current image style name.
$new_style_name: New image style name if renamed, a NULL value will remove the style from the settings.
2 calls to _manualcrop_update_style_name_in_field_widget()
- manualcrop_image_style_delete in ./
manualcrop.module - Implements hook_image_style_delete().
- manualcrop_update_style_name in ./
manualcrop.admin.inc - Style form submit handler; Update the style name in the effect data and in the widgets.
File
- ./
manualcrop.helpers.inc, line 933 - Helper functions for the Manual Crop module.
Code
function _manualcrop_update_style_name_in_field_widget($style_name, $new_style_name = NULL) {
foreach (field_info_fields() as $field) {
if ($field['module'] == 'image') {
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
// Check each instance for processing.
$instance = field_info_instance($entity_type, $field['field_name'], $bundle);
$settings =& $instance['widget']['settings'];
if (manualcrop_supported_widgets($instance['widget']['type']) && (!empty($settings['manualcrop_require_cropping']) || !empty($settings['manualcrop_styles_list']))) {
$list = array();
// Add all existing settings to the list.
if (!empty($settings['manualcrop_require_cropping'])) {
$list['manualcrop_require_cropping'] =& $settings['manualcrop_require_cropping'];
}
if (!empty($settings['manualcrop_styles_list'])) {
$list['manualcrop_styles_list'] =& $settings['manualcrop_styles_list'];
}
// Process all settings.
foreach ($list as $key => &$item) {
if (isset($item[$style_name])) {
if (!is_null($new_style_name)) {
$item[$new_style_name] = $new_style_name;
}
unset($item[$style_name]);
}
else {
// Not processed, so remove it from the list.
unset($list[$key]);
}
}
if (!empty($list)) {
// Settings where updated, save the instance.
field_update_instance($instance);
}
}
}
}
}
}
}