You are here

function field_timer_update_7201 in Field Timer 7.2

Update existing instances with new formatter settings.

File

./field_timer.install, line 33
Install, update and uninstall functions for the Field Timer module.

Code

function field_timer_update_7201(&$sandbox) {
  foreach (field_info_field_map() as $field_name => $short_info) {
    foreach ($short_info['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $bundle) {
        if (in_array($short_info['type'], array(
          'field_timer',
          'datestamp',
          'date',
          'datetime',
        ))) {
          $instance = field_info_instance($entity_type, $field_name, $bundle);
          foreach ($instance['display'] as $display_name => $display) {
            if ($display['type'] == 'field_timer_text') {
              $instance['display'][$display_name]['settings']['granularity_auto'] = $instance['display'][$display_name]['settings']['granularity'];
              unset($instance['display'][$display_name]['settings']['granularity']);
              $instance['display'][$display_name]['settings']['granularity_type'] = 'auto';
              $instance['display'][$display_name]['settings']['granularity_manual'] = array(
                'day' => 'day',
              );
              if (isset($instance['display'][$display_name]['settings']['granularity2'])) {
                $instance['display'][$display_name]['settings']['granularity_auto2'] = $instance['display'][$display_name]['settings']['granularity2'];
                unset($instance['display'][$display_name]['settings']['granularity2']);
                $instance['display'][$display_name]['settings']['granularity_type2'] = 'auto';
                $instance['display'][$display_name]['settings']['granularity_manual2'] = array(
                  'day' => 'day',
                );
              }
              field_update_instance($instance);
            }
          }
        }
      }
    }
  }
}