You are here

function countries_update_7203 in Countries 8

Same name and namespace in other branches
  1. 7.2 countries.install \countries_update_7203()

This updates the display settings to handle the new singular icon formatter.

File

./countries.install, line 256
Install file for Countries module.

Code

function countries_update_7203() {
  if (!module_exists('countryicons')) {
    return;
  }
  $flush = FALSE;
  foreach (field_info_fields() as $field_name => $field) {
    if ($field['type'] == 'country' && !empty($field['bundles'])) {
      foreach ($field['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {
          $changed = FALSE;
          $instance = field_info_instance($entity_type, $field_name, $bundle);
          if (!empty($instance['display'])) {
            foreach ($instance['display'] as $view_mode => &$display) {
              if (strpos($display['type'], 'country_countryicons_') === 0) {
                list(, , $icon_type, $icon_set_name) = explode('_', $display['type'], 4);
                $property = '';
                if ($icon_type == 'imagename') {
                  $property = 'name';
                  $icon_type = 'image';
                }
                $display['type'] = 'country_icon';
                $display['settings']['countryiconset'] = $icon_type . '_' . $icon_set_name;
                $display['settings']['property'] = '';
                $changed = TRUE;
              }
            }
          }
          if ($changed) {
            field_update_instance($instance);
            $flush = TRUE;
          }
        }
      }
    }
  }
  if ($flush) {
    field_cache_clear();
  }
}