Comments

tien.xuan.vo’s picture

damienmckenna’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.43 KB

The problem is that hook_field_info defines 'default_formatter' as 'entityreference_count_formatter_default', which doesn't exist. However, just renaming both formatters will cause problems for anyone currently using the module, so I believe this approach would work better.

Also, please don't forget to change the status to "needs review" when you upload a patch. Thanks!

damienmckenna’s picture

WorldFallz’s picture

Status: Needs review » Needs work

There should be a way to handle this with an update function. Having that bc case there feels hacky to me. I'd like to see what I can dig up before settling on this option.

WorldFallz’s picture

I'm thinking something like this in the .install file should do it:

function entityreference_count_update_7100() {
  $fields = field_read_fields(array('type' => 'entityreference_count'));
  foreach ($fields as $field_name => $info) {
    $full_info = field_info_field($field_name);
    foreach ($full_info['bundles'] as $type => $bundles) {
      foreach ($bundles as $bundle_name) {
        $field_instance_info = field_info_instance($type, $field_name, $bundle_name);
        foreach ($field_instance_info['display'] as $display) {
          if ($display['type'] == 'entityreference_count_default') {
            $display['type'] == 'entityreference_count_formatter_default';
          }
        }
      }
    }
  }
}

What's missing is a way to then save that change.

WorldFallz’s picture

Ok, this should take care of actually saving the change:

function entityreference_count_update_7100() {
  $fields = field_read_fields(array('type' => 'entityreference_count'));
  foreach ($fields as $field_name => $info) {
    $full_info = field_info_field($field_name);
    foreach ($full_info['bundles'] as $type => $bundles) {
      foreach ($bundles as $bundle_name) {
        $field_instance = field_info_instance($type, $field_name, $bundle_name);
        foreach ($field_instance['display'] as $display_name => $display) {
          if ($display['type'] == 'entityreference_count_default') {
            $field_instance['display'][$display_name]['type'] = 'entityreference_count_formatter_default';
          }
        }
        field_update_instance($field_instance);
      }
    }
  }
}

Patch to follow when I get a chance.

WorldFallz’s picture

StatusFileSize
new5.67 KB

And, patch attached. This takes care of all the cases from the original patch, as well as the new formatter defined in #2572811: Provide options for link and label in default field formatter.

WorldFallz’s picture

StatusFileSize
new5.66 KB

Now with less unnecessary whitespace, lol.

WorldFallz’s picture

Status: Needs work » Needs review
WorldFallz’s picture

StatusFileSize
new5.66 KB

And rerolled due to a number of recent commits.

  • WorldFallz committed 06aac1f on 7.x-1.x
    Issue #2105435 by WorldFallz, DamienMcKenna, tien.xuan.vo: Field is not...
WorldFallz’s picture

Status: Needs review » Fixed

Tested the update a bunch of times and all seems good. Thanks everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.