function media_gallery_update_7009 in Media Gallery 7
Same name and namespace in other branches
- 7.2 media_gallery.install \media_gallery_update_7009()
Update old per-view-mode media_gallery_* field formatters to the generic media_gallery formatter with a setting.
File
- ./
media_gallery.install, line 1266 - Install file for media_gallery. Includes field and instance definitions.
Code
function media_gallery_update_7009() {
$instances = array();
$fields = field_read_fields(array(
'type' => 'media',
), array(
'include_inactive' => TRUE,
));
foreach ($fields as $field) {
$instances = array_merge($instances, field_read_instances(array(
'field_id' => $field['id'],
), array(
'include_inactive' => TRUE,
)));
}
foreach ($instances as $instance) {
$update_instance = FALSE;
foreach ($instance['display'] as $view_mode => $display) {
if (in_array($display['type'], array(
'media_gallery_thumbnail',
'media_gallery_lightbox',
'media_gallery_detail',
'media_gallery_block_thumbnail',
'media_gallery_collection_thumbnail',
))) {
$update_instance = TRUE;
$instance['display'][$view_mode]['type'] = 'media_gallery';
$instance['display'][$view_mode]['settings'] = array(
'file_view_mode' => $display['type'],
);
}
}
if ($update_instance) {
field_update_instance($instance);
}
}
}