function asin_update_7000 in Amazon Product Advertisement API 7
Same name and namespace in other branches
- 7.2 asin/asin.install \asin_update_7000()
Fix the formatter machine names for asin field displays.
File
- asin/
asin.install, line 37 - Install, update and uninstall functions for the asin module.
Code
function asin_update_7000(&$sandbox) {
if (!isset($sandbox['progress'])) {
// Find all ASIN field instances.
foreach (field_info_fields() as $field_name => $field) {
if ($field['type'] == 'asin') {
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$sandbox['instances'][] = array(
'entity_type' => $entity_type,
'bundle' => $bundle,
'field_name' => $field_name,
);
}
}
}
}
$sandbox['progress'] = 0;
$sandbox['max'] = count($sandbox['instances']);
// If there are no field instances to update, return.
if (!$sandbox['max']) {
return;
}
}
$instance = $sandbox['instances'][$sandbox['progress']];
$instance = field_read_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']);
$updated = FALSE;
foreach ($instance['display'] as &$display) {
if (in_array($display['type'], array(
'default',
'details',
'thumbnail',
'medium',
'large',
'inline',
))) {
$updated = TRUE;
$display['type'] = 'asin_' . $display['type'];
}
}
if ($updated) {
// Only trigger instance update if we actually changed anything.
field_update_instance($instance);
}
$sandbox['progress']++;
$sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
}