I got this issue reported in Entityforms #1975266: Features export should autodetect fields

I tested it and basically fields were not be exported with an Entityform Type(which uses 'bundle of') when using features 2.x branch. I also confirmed this is happening with Profile2 types. Both use the EntityDefaultFeaturesController.

I tracked down the problem to EntityDefaultFeaturesController->export().

        // If this is a bundle of a fieldable entity, add its fields to the pipe.
        if (!empty($this->info['bundle of'])) {
          $fields = field_info_instances($this->info['bundle of'], $entity->{$this->bundleKey});
          foreach ($fields as $name => $field) {
            $pipe['field'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}";
          }
        }

This works fine for Features 1.x but not for 2.x.

I found that Features own implementation to export content types also exports the field instances not just the bases.

From node_features_export().

 $fields = field_info_instances('node', $type);
      foreach ($fields as $name => $field) {
        $pipe['field'][] = "node-{$field['bundle']}-{$field['field_name']}";
        $pipe['field_instance'][] = "node-{$field['bundle']}-{$field['field_name']}";
      }

Added the extra line to extra line to also export the field instances and this then exports the fields with Features 2.x

        // If this is a bundle of a fieldable entity, add its fields to the pipe.
        if (!empty($this->info['bundle of'])) {
          $fields = field_info_instances($this->info['bundle of'], $entity->{$this->bundleKey});
          foreach ($fields as $name => $field) {
            $pipe['field'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}";
            $pipe['field_instance'][] = "{$field['entity_type']}-{$field['bundle']}-{$field['field_name']}";
          }
        }

Patch attached.

CommentFileSizeAuthor
entity-export_field_instances.patch587 bytestedbow

Comments

ciss’s picture

Using features-7.x-2.0-rc1 this patch works great.
It also still applies against entity-7.x-1.1+2-dev (2013-May-20).

coline’s picture

Thank you tedbow for sharing your patch.
It worked perfectly with me :
- Entity API : 7.x-1.6
- EntityForm : 7.x-2.0-rc1
- Features : 7.x-2.0-rc1

ciss’s picture

Status: Needs review » Reviewed & tested by the community

  • fago committed 3d9ca14 on 7.x-1.x authored by tedbow
    Issue #1986736 by tedbow, ciss, coline: EntityDefaultFeaturesController...
fago’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed!

Status: Fixed » Closed (fixed)

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