You are here

function name_update_7002 in Name Field 7

Updates the field formatters to the new singular formatter type.

File

./name.install, line 167
Standard installation functions for name.

Code

function name_update_7002() {
  foreach (field_info_fields() as $field_name => $field) {
    if ($field['type'] == 'name' && !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) {
              list($name, $output, $format) = explode('_', $display['type'] . '__');
              if ($name == 'name') {
                switch ($output) {
                  case 'default':
                  case 'plain':
                  case 'raw':
                    $display['type'] = 'name_formatter';
                    $display['settings']['output'] = $output;
                    if (empty($format)) {
                      $format = 'default';
                    }
                    $display['settings']['format'] = $format;

                    // Ensure that the display settings for the two new fields
                    // are set while we are updating the other display settings.
                    $defaults = array(
                      'markup' => 0,
                      'multiple' => 'default',
                      'multiple_delimiter' => ', ',
                      // And or symbol.
                      'multiple_and' => 'text',
                      // contextual, always, never.
                      'multiple_delimiter_precedes_last' => 'never',
                      'multiple_el_al_min' => 3,
                      'multiple_el_al_first' => 1,
                    );
                    foreach ($defaults as $key => $value) {
                      if (!isset($display['settings'][$key])) {
                        $display['settings'][$key] = $value;
                      }
                    }
                    $changed = TRUE;
                    break;
                  default:
                }
              }
            }
          }
          if ($changed) {
            field_update_instance($instance);
          }
        }
      }
    }
  }

  // The new formatter settings will not save unless we clear the caches.
  field_cache_clear();
  cache_clear_all();
}